File: map_editcolormap.py

package info (click to toggle)
sunpy 7.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,584 kB
  • sloc: python: 41,702; ansic: 1,710; makefile: 39
file content (39 lines) | stat: -rw-r--r-- 1,530 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
"""
===============================================
Editing the colormap and normalization of a Map
===============================================

How to edit the display of a map.
"""
import matplotlib
import matplotlib.colors as colors
import matplotlib.pyplot as plt

import sunpy.map
from sunpy.data.sample import AIA_171_IMAGE

###############################################################################
# We start with the sample data.

aiamap = sunpy.map.Map(AIA_171_IMAGE)

###############################################################################
# All plot settings for a map are stored in the ``plot_settings`` attribute.
# How a Map is displayed is determined by its colormap, which sets the colors
# , and the normalization, which sets how data values are translated to colors.
# Let's replace the colormap and normalization.

aiamap.plot_settings['cmap'] = matplotlib.colormaps['Greys_r']
aiamap.plot_settings['norm'] = colors.LogNorm(100, aiamap.max())

###############################################################################
# To see all of the colormaps sunpy provides see `sunpy.visualization.colormaps`.
# Matplotlib provides a number of `colormaps <https://matplotlib.org/stable/gallery/color/colormap_reference.html>`__
# and `normalizations <https://matplotlib.org/stable/users/explain/colors/colormapnorms.html>`__.
# For more advanced normalizations see `astropy.visualization`.

fig = plt.figure()
ax = fig.add_subplot(projection=aiamap)
aiamap.plot(axes=ax)
plt.colorbar()
plt.show()