Using the sunpy Colormaps with matplotlib#

How you can use the sunpy colormaps with matplotlib.

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

import sunpy.visualization.colormaps as cm

When the sunpy colormaps are imported, the sunpy colormaps are registered with matplotlib. It is now possible to access the colormaps with the following command.

You can get the list of all sunpy colormaps with:

print(cm.cmlist.keys())
dict_keys(['goes-rsuvi94', 'goes-rsuvi131', 'goes-rsuvi171', 'goes-rsuvi195', 'goes-rsuvi284', 'goes-rsuvi304', 'sdoaia94', 'sdoaia131', 'sdoaia171', 'sdoaia193', 'sdoaia211', 'sdoaia304', 'sdoaia335', 'sdoaia1600', 'sdoaia1700', 'sdoaia4500', 'sohoeit171', 'sohoeit195', 'sohoeit284', 'sohoeit304', 'soholasco2', 'soholasco3', 'sswidlsoholasco2', 'sswidlsoholasco3', 'stereocor1', 'stereocor2', 'stereohi1', 'stereohi2', 'yohkohsxtal', 'yohkohsxtwh', 'hinodexrt', 'hinodesotintensity', 'trace171', 'trace195', 'trace284', 'trace1216', 'trace1550', 'trace1600', 'trace1700', 'traceWL', 'hmimag', 'irissji1330', 'irissji1400', 'irissji1600', 'irissji2796', 'irissji2832', 'irissji5000', 'irissjiFUV', 'irissjiNUV', 'irissjiSJI_NUV', 'kcor', 'rhessi', 'std_gamma_2', 'euvi171', 'euvi195', 'euvi284', 'euvi304', 'solar orbiterfsi174', 'solar orbiterfsi304', 'solar orbiterhri_euv174', 'solar orbiterhri_lya1216'])

Let’s now create a data array.

delta = 0.025
x = y = np.arange(-3.0, 3.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2) * 2

Let’s now plot the results with the colormap.

fig, ax = plt.subplots()
im = ax.imshow(
    Z, interpolation='bilinear', cmap=sdoaia171,
    origin='lower', extent=[-3, 3, -3, 3],
    vmax=abs(Z).max(), vmin=-abs(Z).max()
)
plt.show()
sunpy matplotlib colormap

Total running time of the script: (0 minutes 0.160 seconds)

Gallery generated by Sphinx-Gallery