Skip to content

Commit

Permalink
Merge pull request #37 from zssherman/example_bars
Browse files Browse the repository at this point in the history
ADD: Example plot cvd colorbars.py
  • Loading branch information
zssherman authored Aug 21, 2024
2 parents b25a762 + e1a6d63 commit 35b077f
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ci/environment-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ channels:
- conda-forge
dependencies:
- numpydoc
- matplotlib
- pydata-sphinx-theme
- nbsphinx
- ipython
Expand All @@ -13,7 +14,11 @@ dependencies:
- myst-nb
- myst-parser
- sphinx-design
- sphinx-gallery
- sphinx-copybutton
- sphinx<7.2
- pip
- pip:
- ablog
- sphinxext-opengraph
- -e ..
8 changes: 8 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
1 change: 1 addition & 0 deletions docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ hidden:
---
usage
api
source/auto_examples/index.rst
contributing
```

Expand Down
4 changes: 4 additions & 0 deletions examples/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Example Gallery
===============

This gallery houses examples on the different colormaps present in cmweather.
102 changes: 102 additions & 0 deletions examples/plot_cvd_colorbars.py
Original file line number Diff line number Diff line change
@@ -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'])

0 comments on commit 35b077f

Please sign in to comment.