diff --git a/ci/environment-docs.yml b/ci/environment-docs.yml index 014f770..e50db6b 100644 --- a/ci/environment-docs.yml +++ b/ci/environment-docs.yml @@ -3,6 +3,7 @@ channels: - conda-forge dependencies: - numpydoc + - matplotlib - pydata-sphinx-theme - nbsphinx - ipython @@ -13,7 +14,11 @@ dependencies: - myst-nb - myst-parser - sphinx-design + - sphinx-gallery + - sphinx-copybutton + - sphinx<7.2 - pip - pip: + - ablog - sphinxext-opengraph - -e .. diff --git a/docs/source/conf.py b/docs/source/conf.py index 01731e1..bbf449b 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -40,14 +40,22 @@ 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.extlinks', + 'sphinx_gallery.gen_gallery', 'numpydoc', 'myst_nb', 'IPython.sphinxext.ipython_console_highlighting', 'IPython.sphinxext.ipython_directive', 'nbsphinx', 'sphinx_design', + 'myst_nb', + 'ablog', ] +sphinx_gallery_conf = { + 'examples_dirs': '../../examples', + 'gallery_dirs': 'source/auto_examples', + 'abort_on_example_error': True, +} # MyST config myst_enable_extensions = ['amsmath', 'colon_fence', 'deflist', 'html_image'] diff --git a/docs/source/index.md b/docs/source/index.md index 2ca491a..4c69549 100644 --- a/docs/source/index.md +++ b/docs/source/index.md @@ -10,6 +10,7 @@ hidden: --- usage api +source/auto_examples/index.rst contributing ``` diff --git a/examples/README.rst b/examples/README.rst new file mode 100644 index 0000000..dd88ccc --- /dev/null +++ b/examples/README.rst @@ -0,0 +1,4 @@ +Example Gallery +=============== + +This gallery houses examples on the different colormaps present in cmweather. diff --git a/examples/plot_cvd_colorbars.py b/examples/plot_cvd_colorbars.py new file mode 100644 index 0000000..fb0b1df --- /dev/null +++ b/examples/plot_cvd_colorbars.py @@ -0,0 +1,102 @@ +""" +=================================== +Choose a CVD Colormap for your Plot +=================================== + +This is an example of some of the CVD friendly colormaps in cmweather, +and how to add them to your own plots. + +""" +print(__doc__) + +# Author: Max Grover and Zach Sherman +# License: BSD 3 clause + +import matplotlib +import matplotlib.pyplot as plt +import numpy as np + +import cmweather # noqa + +matplotlib.rcParams.update({'font.family': 'Arial'}) + +###################################### +# **Plot the available colormaps** +# +# Let's see which CVD colormaps are available directly from cmweather! +# We use a helper function from matplotlib to plot this. + +# Setup some helper functions and ranges to visualize our colormaps, from matplotlib +gradient = np.linspace(0, 1, 256) +gradient = np.vstack((gradient, gradient)) + + +def plot_color_gradients(cmap_category, cmap_list): + # Create figure and adjust figure height to number of colormaps + nrows = len(cmap_list) + figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22 + fig, axs = plt.subplots(nrows=nrows, figsize=(6.4, figh)) + fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh, left=0.4, right=0.99) + + axs[0].set_title(cmap_category, fontsize=14) + + for ax, cmap_name in zip(axs, cmap_list): + ax.imshow(gradient, aspect='auto', cmap=f"{cmap_name}") + if cmap_name == 'plasmidis': + ax.text( + -0.01, + 0.5, + f"{'plasmidis'}", + va='center', + ha='right', + fontsize=10, + transform=ax.transAxes, + ) + else: + ax.text( + -0.01, + 0.5, + f"{cmap_name}", + va='center', + ha='right', + fontsize=10, + transform=ax.transAxes, + ) + + # Turn off *all* ticks & spines, not just the ones with colormaps. + for ax in axs: + ax.set_axis_off() + + +###################################### +# **Color Vision Deficiency (CVD) Friendly Colormaps** +# +# We recommend starting with these CVD friendly colormaps. +# These colormaps are the most inclusive, and should be used where +# possible. + +####################################### +# **Reflectivity Colormaps** +# +# These CVD colormaps were created for equivalent reflectivity factor. + +(r'$H_{2}$') +plot_color_gradients( + r'CVD-Friendly $Z_{e}$ Colormaps', + ['LangRainbow12', 'HomeyerRainbow', 'ChaseSpectral', 'SpectralExtended'], +) + +######################################## +# **Velocity Colormaps** +# +# These CVD colormaps were created for mean Doppler velocity. + +plot_color_gradients('CVD-Friendly Velocity Colormaps', ['balance', 'twilight_shifted']) + +######################################## +# **Polarization Colormaps** +# +# These CVD colormaps were created for polarization moments such as +# differential reflectivity and depolarization ratio. + +plot_color_gradients('CVD-Friendly Polarization Colormaps', ['CM_depol', 'plasmidis'])