Using the SunPy Colormaps with matplotlib

How you can use the SunPy colormaps with matplotlib.

import numpy as np
import matplotlib.pyplot as plt

import 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

sdoaia171 = plt.get_cmap('sdoaia171')

You can get the list of all SunPy colormaps with:



dict_keys(['sdoaia94', 'sdoaia131', 'sdoaia171', 'sdoaia193', 'sdoaia211', 'sdoaia304', 'sdoaia335', 'sdoaia1600', 'sdoaia1700', 'sdoaia4500', 'sohoeit171', 'sohoeit195', 'sohoeit284', 'sohoeit304', 'soholasco2', 'soholasco3', 'sswidlsoholasco2', 'sswidlsoholasco3', 'stereocor1', 'stereocor2', 'stereohi1', 'stereohi2', 'rhessi', 'yohkohsxtal', 'yohkohsxtwh', 'hinodexrt', 'hinodesotintensity', 'trace171', 'trace195', 'trace284', 'trace1216', 'trace1550', 'trace1600', 'trace1700', 'traceWL', 'hmimag', 'irissji1330', 'irissji1400', 'irissji1600', 'irissji2796', 'irissji2832', 'irissji5000', 'irissjiFUV', 'irissjiNUV', 'irissjiSJI_NUV', 'kcor'])

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())

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

Gallery generated by Sphinx-Gallery