Skip to content

Commit

Permalink
add 3 examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jukent committed Jun 29, 2023
1 parent ca94f5f commit 9621615
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 3 deletions.
Binary file added docs/_static/thumbnails/add_major_minor_ticks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/thumbnails/add_right_hand_axis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions docs/examples/add_major_minor_ticks.ipynb

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions docs/examples/add_right_hand_axis.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# `add_right_hand_axis`\n",
"\n",
"This notebook is a simple example of the GeoCAT-viz function <a href=\"../user_api/generated/geocat.viz.util.add_right_hand_axis.html#geocat-viz.util.add_right_hand_axis\">add_right_hand_axis</a>."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import xarray as xr\n",
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"from cartopy.mpl.ticker import LatitudeFormatter\n",
"\n",
"import geocat.datafiles as gdf\n",
"import geocat.viz as gv"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Read in Data\n",
"\n",
"# Open a netCDF data file using xarray default engine and load the data into an xarray\n",
"ds = xr.open_dataset(gdf.get('netcdf_files/atmos.nc'), decode_times=False)\n",
"\n",
"# Select zonal wind\n",
"u = ds.U.isel(time=0)\n",
"\n",
"# Get zonal mean\n",
"u_av = u.mean(dim='lon')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Plot:\n",
"\n",
"# Generate figure (set its size (width, height) in inches)\n",
"plt.figure(figsize=(9, 10))\n",
"ax1 = plt.gca()\n",
"\n",
"# Plot contour lines\n",
"contours = u_av.plot.contour(ax=ax1,\n",
" levels=13,\n",
" vmin=-8,\n",
" vmax=40,\n",
" colors='black',\n",
" linewidths=0.5,\n",
" linestyles='solid',\n",
" add_labels=False)\n",
"\n",
"# Add second axis to plot heights (heights chosen arbitrarily)\n",
"gv.add_right_hand_axis(ax1,\n",
" label=\"Right Hand Axis\",\n",
" ylim=(0, 13),\n",
" yticks=np.array([4, 8]),\n",
" ticklabelsize=15,\n",
" axislabelsize=21)\n",
"\n",
"plt.show();"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "geocat_viz_build",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.0"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
70 changes: 70 additions & 0 deletions docs/examples/set_tick_direction_spine_visibility.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# `set_tick_direction_spine_visibility`\n",
"\n",
"This notebook is a simple example of the GeoCAT-viz function <a href=\"../user_api/generated/geocat.viz.util.set_tick_direction_spine_visibility.html#geocat-viz.util.set_tick_direction_spine_visibility\">set_tick_direction_spine_visibility</a>."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Import packages:\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import geocat.viz as gv"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Plot:\n",
"\n",
"# Create figure and axis\n",
"fig, ax = plt.subplots(figsize=(6, 6))\n",
"\n",
"# Use geocat.viz.util convenience function to set spines visibility\n",
"gv.set_tick_direction_spine_visibility(ax,\n",
" tick_direction='in',\n",
" top_spine_visible=False,\n",
" right_spine_visible=False)\n",
"\n",
"# Display Plot\n",
"plt.tight_layout()\n",
"plt.show();"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "geocat_viz_build",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.0"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
12 changes: 12 additions & 0 deletions docs/gallery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@
- title: 'add_lat_lon_ticklabels'
path: examples/add_lat_lon_ticklabels.ipynb
thumbnail: _static/thumbnails/add_lat_lon_ticklabels.png

- title: 'set_tick_direction_spine_visibility'
path: examples/set_tick_direction_spine_visibility.ipynb
thumbnail: _static/thumbnails/set_tick_direction_spine_visibility.png

- title: 'add_right_hand_axis'
path: examples/add_right_hand_axis.ipynb
thumbnail: _static/thumbnails/add_right_hand_axis.png

- title: 'add_major_minor_ticks'
path: examples/add_major_minor_ticks.ipynb
thumbnail: _static/thumbnails/add_major_minor_ticks.png
12 changes: 9 additions & 3 deletions src/geocat/viz/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def set_tick_direction_spine_visibility(ax,
Examples
--------
All usage examples are within the GeoCAT-Examples Gallery. To see more usage cases, search the function on the `website <https://geocat-examples.readthedocs.io/en/latest/index.html>`_.
See this example notebook: :doc:`../../examples/set_tick_direction_spine_visibility`.
More in-depth plotting examples that utilize this function are in the GeoCAT-Examples Gallery. To see more usage cases, search the function on the `website <https://geocat-examples.readthedocs.io/en/latest/index.html>`_.
- `NCL_box_2.py <https://geocat-examples.readthedocs.io/en/latest/gallery/Boxplots/NCL_box_2.html?highlight=set_tick_direction_spine_visibility>`_
"""
Expand Down Expand Up @@ -199,7 +201,9 @@ def add_right_hand_axis(ax,
Examples
--------
All usage examples are within the GeoCAT-Examples Gallery. To see more usage cases, search the function on the `website <https://geocat-examples.readthedocs.io/en/latest/index.html>`_.
See this example notebook: :doc:`../../examples/add_right_hand_axis`.
More in-depth plotting examples that utilize this function are in the GeoCAT-Examples Gallery. To see more usage cases, search the function on the `website <https://geocat-examples.readthedocs.io/en/latest/index.html>`_.
- `NCL_coneff_8.py <https://geocat-examples.readthedocs.io/en/latest/gallery/Contours/NCL_coneff_8.html?highlight=add_right_hand_axis>`_
"""
Expand Down Expand Up @@ -404,7 +408,9 @@ def add_major_minor_ticks(ax: typing.Union[matplotlib.axes.Axes,
Examples
--------
All usage examples are within the GeoCAT-Examples Gallery. To see more usage cases, search the function on the `website <https://geocat-examples.readthedocs.io/en/latest/index.html>`_.
See this example notebook: :doc:`../../examples/add_major_minor_ticks`.
More in-depth plotting examples that utilize this function are in the GeoCAT-Examples Gallery. To see more usage cases, search the function on the `website <https://geocat-examples.readthedocs.io/en/latest/index.html>`_.
- `NCL_bar_2.py <https://geocat-examples.readthedocs.io/en/latest/gallery/Bar/NCL_bar_2.html?highlight=add_major_minor_ticks>`_
Expand Down

0 comments on commit 9621615

Please sign in to comment.