-
Notifications
You must be signed in to change notification settings - Fork 228
Add tutorial to show interactive data visualization via 'panel' #2498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
f3e496b
Add basic code for tutorial showing the 'panel'
yvonnefroehlich 8e0e0dd
Remove section 'Add a grid'
yvonnefroehlich 9274b85
Fix code style - add blank line
yvonnefroehlich 0133512
[format-command] fixes
actions-bot d55d7cf
Adjust thumbnail_number
yvonnefroehlich dccdf74
Add 'panel' as a dependency
yvonnefroehlich fdf180e
Add 'panel' as dependency
yvonnefroehlich 8a50bde
Fix typos
yvonnefroehlich b548efa
Add missing comma
yvonnefroehlich c5d3e82
Fix highlighting
yvonnefroehlich 5149655
Fix link
yvonnefroehlich 28a72df
Improve docs
yvonnefroehlich bde882b
Add more docs
yvonnefroehlich 3919f03
Adjust thubnail_number
yvonnefroehlich b046aac
Add code for third part (add grid)
yvonnefroehlich c9b213e
Fix coding style
yvonnefroehlich a4c7c2a
Remove blank line
yvonnefroehlich 1cec47e
Do not include 'panel' as an optional dependency in 'pyproject.py'
yvonnefroehlich 55b7203
Do not include 'panel' as an optional dependency in 'install.rst'
yvonnefroehlich 0f25508
Improve link to 'panel'
yvonnefroehlich 66b0087
Move 'panel' to 'Dev dependencies (building documentation)'
yvonnefroehlich d004415
Fix list - add blank line
yvonnefroehlich cea4021
Move 'panel' to 'Dev dependencies (building documentation)'
yvonnefroehlich 84541a4
Remove 'panel' from 'conf.py'
yvonnefroehlich 8a5c31a
Fix typo (code review)
yvonnefroehlich 8f93932
Rename 'panel_extension.py' -> 'working_with_panel.py'
8de8053
Merge branch 'main' into add-tutorial-panel
yvonnefroehlich 7a8a5aa
Improve and add documentation
yvonnefroehlich 8dcd549
Merge branch 'main' into add-tutorial-panel
yvonnefroehlich 99a1fec
Adjust G projection for static map
yvonnefroehlich afbf83f
Add docs for grid section
yvonnefroehlich b862ba6
Improve docs for dynamic section
yvonnefroehlich 36d6931
Use alwaysthe same size
yvonnefroehlich 3a050bc
Add docs for static section
yvonnefroehlich def14dd
Improve docs for introduction
yvonnefroehlich e314ea6
Improve docs
yvonnefroehlich be31019
Use 'note' highlighting (code review)
yvonnefroehlich 15dbff7
Fix line length
yvonnefroehlich 009228a
Add 'panel' as a dependency in 'ci_docs.yml'
yvonnefroehlich 4469d2e
Merge branch 'main' into add-tutorial-panel
yvonnefroehlich ed45c1e
Change 'dynamic' -> 'interactive'
yvonnefroehlich 656b0f5
Change 'dynamic' -> 'interactive'
yvonnefroehlich 5b7eff9
Change 'dynamic' -> 'interactive'
yvonnefroehlich d830c28
Calculate min and max without numpy
yvonnefroehlich f3431e0
Adjust building string for projection argument
yvonnefroehlich 40589ec
Adjust building string for projection argument
yvonnefroehlich 3e3ea36
Remove white spaces around "/"
yvonnefroehlich ea81b1d
Update file name in introduction
yvonnefroehlich c3fd8e7
Fix length of underline of title
yvonnefroehlich fe456aa
Adjust 'series' parameter of 'makecpt'
yvonnefroehlich 49c0eb2
Fix line length
yvonnefroehlich 0e6ef65
Remove file name in introduction
yvonnefroehlich 68ba2e5
Fix coding style - 'series' argument seems to fit in one line
yvonnefroehlich 71ddb12
Remove 'r' at the beginning of the docstrings (code review)
yvonnefroehlich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,7 @@ jobs: | |
make | ||
pip | ||
myst-parser | ||
panel | ||
sphinx | ||
sphinx-copybutton | ||
sphinx-design | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
""" | ||
Interactive data visualization using ``Panel`` | ||
============================================== | ||
|
||
.. note:: | ||
|
||
Please run the following code examples in a notebook environment | ||
otherwise the interactive parts of this tutorial will not work. You can | ||
use the button "Download Jupyter notebook" at the bottom of this page | ||
to download this script as a Jupyter notebook. | ||
|
||
The library `Panel <https://panel.holoviz.org/index.html>`__ can be used to | ||
create interactive dashboards by connecting user-defined widgets to plots. | ||
``Panel`` can be used as an extension to Jupyter notebook/lab. | ||
|
||
This tutorial is split into three parts: | ||
|
||
- Make a static map | ||
- Make an interactive map | ||
- Add a grid for Earth relief | ||
""" | ||
|
||
# sphinx_gallery_thumbnail_number = 1 | ||
|
||
|
||
# Import the required packages | ||
import numpy as np | ||
import panel as pn | ||
import pygmt | ||
|
||
pn.extension() | ||
|
||
|
||
############################################################################### | ||
# Make a static map | ||
# ----------------- | ||
# The `Orthographic projection | ||
# <https://www.pygmt.org/dev/projections/azim/azim_orthographic.html>`__ | ||
# can be used to show the Earth as a globe. Land and water masses are | ||
# filled with colors via the ``land`` and ``water`` parameters of | ||
# :meth:`pygmt.Figure.coast`, respectively. Coastlines are added using the | ||
# ``shorelines`` parameter. | ||
|
||
# Create a new instance or object of the pygmt.Figure() class | ||
fig = pygmt.Figure() | ||
fig.coast( | ||
# Orthographic projection (G) with projection center at 0° East and | ||
# 15° North and a width of 12 centimeters | ||
projection="G0/15/12c", | ||
region="g", # global | ||
frame="g30", # Add frame and gridlines in steps of 30 degrees on top | ||
land="gray", # Color land masses in "gray" | ||
water="lightblue", # Color water masses in "lightblue" | ||
# Add coastlines with a 0.25 points thick pen in "gray50" | ||
shorelines="1/0.25p,gray50", | ||
) | ||
fig.show() | ||
|
||
|
||
############################################################################### | ||
# Make an interactive map | ||
# ----------------------- | ||
# To generate a rotation of the Earth around the vertical axis, the central | ||
# longitude of the Orthographic projection is varied iteratively in steps of | ||
# 10 degrees. The library ``Panel`` is used to create an interactive dashboard | ||
# with a slider (works only in a notebook environment, e.g. Jupyter notebook). | ||
|
||
# Create a slider | ||
slider_lon = pn.widgets.DiscreteSlider( | ||
name="Central longitude", # Give name for quantity shown at the slider | ||
options=list(np.arange(0, 361, 10)), # Range corresponding to longitude | ||
value=0, # Set start value | ||
) | ||
|
||
|
||
# Define a function for plotting the single slices | ||
@pn.depends(central_lon=slider_lon) | ||
def view(central_lon): | ||
# Create a new instance or object of the pygmt.Figure() class | ||
fig = pygmt.Figure() | ||
fig.coast( | ||
# Vary the central longitude used for the Orthographic projection | ||
projection=f"G{central_lon}/15/12c", | ||
region="g", | ||
frame="g30", | ||
land="gray", | ||
water="lightblue", | ||
shorelines="1/0.25p,gray50", | ||
) | ||
return fig | ||
|
||
|
||
# Make an interactive dashboard | ||
pn.Column(slider_lon, view) | ||
|
||
|
||
############################################################################### | ||
# Add a grid for Earth relief | ||
# --------------------------- | ||
# Instead of using colors as fill for the land and water masses a grid can be | ||
# displayed. Here, the Earth relief is shown by color-coding the elevation. | ||
|
||
# Download a grid for Earth relief with a resolution of 10 arc-minutes | ||
grd_relief = pygmt.datasets.load_earth_relief(resolution="10m") | ||
|
||
# Create a slider | ||
slider_lon = pn.widgets.DiscreteSlider( | ||
name="Central longitude", | ||
options=list(np.arange(0, 361, 10)), | ||
value=0, | ||
) | ||
|
||
|
||
# Define a function for plotting the single slices | ||
@pn.depends(central_lon=slider_lon) | ||
def view(central_lon): | ||
# Create a new instance or object of the pygmt.Figure() class | ||
fig = pygmt.Figure() | ||
# Set up a colormap for the elevation in meters | ||
pygmt.makecpt( | ||
cmap="oleron", | ||
# minimum, maximum, step | ||
series=[int(grd_relief.data.min()) - 1, int(grd_relief.data.max()) + 1, 100], | ||
) | ||
# Plot the grid for the elevation | ||
fig.grdimage( | ||
projection=f"G{central_lon}/15/12c", | ||
region="g", | ||
grid=grd_relief, # Use grid downloaded above | ||
cmap=True, # Use colormap defined above | ||
frame="g30", | ||
) | ||
# Add a horizontal colorbar for the elevation | ||
# with annotations (a) in steps of 2000 and ticks (f) in steps of 1000 | ||
# and labels (+l) at the x-axis "Elevation" and y-axis "m" (meters) | ||
fig.colorbar(frame=["a2000f1000", "x+lElevation", "y+lm"]) | ||
return fig | ||
|
||
|
||
# Make an interactive dashboard | ||
pn.Column(slider_lon, view) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.