/
finegrained_plot.py
75 lines (60 loc) · 2.81 KB
/
finegrained_plot.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
===============================
Fine grained Plotting Features
===============================
An example to show control over various plotting features.
"""
###############################################################################
# Import the necessary modules for plotting.
import astropy.units as u
from astropy.coordinates import SkyCoord
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
import sunpy.map
from sunpy.data.sample import AIA_171_IMAGE
###############################################################################
# SkyCoord module provides flexible celestial coordinate representation and a
# draw_limb method draws an edge as seen against the dark sky background. Date of the
# image taken can also be displayed in the plot.
aiamap = sunpy.map.Map(AIA_171_IMAGE)
bottom_left = SkyCoord(-400*u.arcsec, -900*u.arcsec, frame=aiamap.coordinate_frame)
top_right = SkyCoord(800*u.arcsec, 700*u.arcsec, frame=aiamap.coordinate_frame)
aiamap_sub = aiamap.submap(bottom_left, top_right)
title_obsdate = aiamap_sub.date.strftime('%Y-%b-%d %H:%M:%S')
###############################################################################
# The SunPy map peek method shows a helioprojective grid by default.
# This is sometimes not desired, and instead a heliographic Stonyhurst grid might
# be required. Although maps offer a simple way to include a Stonyhurst grid, often
# times we want more control over the Stonyhurst type. The example below illustrates
# some aspects of how a map plot can be altered as desired. For more information
# regarding the axis and grid settings, go to `Ticks, tick labels and grid lines
# <http://docs.astropy.org/en/stable/visualization/wcsaxes/ticks_labels_grid.html>`_ in astropy.
fig = plt.figure(figsize=(6, 6))
ax = plt.subplot(projection=aiamap_sub)
aiamap_sub.plot()
aiamap_sub.draw_limb(color='white', linewidth=2, linestyle='dashed')
# To have more control over the Heliographic Stonyhurst grid,
# the axes object properties can be changed directly
overlay = ax.get_coords_overlay('heliographic_stonyhurst')
lon = overlay[0]
lat = overlay[1]
lon.set_ticks_visible(False)
lat.set_ticks_visible(False)
lat.set_ticklabel_visible(False)
lon.set_ticklabel_visible(False)
lon.coord_wrap = 180
lon.set_major_formatter('dd')
# Plot the Heliographic Stonyhurst grid
overlay.grid(color='blue', linewidth=2, linestyle='dashed')
# Switch off the helioprojective grid
ax.grid(False)
# Change how the helioprojective grid tick labels are formatted
tx, ty = ax.coords
# Use integer coordinates for either axis.
tx.set_major_formatter('s')
ty.set_major_formatter('s')
ax.set_title('AIA 171 $\AA$ {}'.format(title_obsdate))
ax.set_ylabel('Helioprojective Latitude [arcsec]')
ax.set_xlabel('Helioprojective Longitude [arcsec]')
plt.colorbar(fraction=0.045, pad=0.03, label='DN', ax=ax)
plt.show()