File: sunpy_matplotlib_colormap.py

package info (click to toggle)
sunpy 4.1.2-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 11,972 kB
  • sloc: python: 39,301; ansic: 1,780; makefile: 35
file content (42 lines) | stat: -rw-r--r-- 1,350 bytes parent folder | download
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
"""
=========================================
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.

plt.figure()
im = plt.imshow(Z, interpolation='bilinear', cmap=sdoaia171,
                origin='lower', extent=[-3, 3, -3, 3],
                vmax=abs(Z).max(), vmin=-abs(Z).max())
plt.show()