File: sunpy_matplotlib_colormap.py

package info (click to toggle)
sunpy 7.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,592 kB
  • sloc: python: 41,765; ansic: 1,710; makefile: 39
file content (44 lines) | stat: -rw-r--r-- 1,343 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
=========================================
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.

sdoaia171 = matplotlib.colormaps['sdoaia171']

###############################################################################
# You can get the list of all sunpy colormaps with:

print(cm.cmlist.keys())

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