Set Axis Range When Plotting a Map¶
In this example we are going to look at how to set the axes
range using Matplotlib’s
set_ylim when plotting a
Map with WCSAxes.
import matplotlib.pyplot as plt import astropy.units as u from astropy.coordinates import SkyCoord import sunpy.data.sample import sunpy.map
Lets start by creating a Map from the sample data.
aia_map = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE)
Now lets say for example we are only interested in plotting a certain region
of this Map. One way this could be done is to create a submap over the region
of interest and then plotting that. Another useful way is to set the axes
range over which to plot using Matplotlib’s
The axes that Matplotlib uses is in pixel coordinates (e.g. of image data array)
rather than world coordinates (e.g. in arcsecs) so we need to define our limits that
are passed to
set_ylim to pixel coordinates.
We can define our limits we want to use in world coordinates and then work out what pixel
coordinates these correspond to.
Lets choose x-limits and y-limits in arcsecs that we are interested in.
We can then convert these into a SkyCoord which can be passed to
determine which pixel coordinates these represent on the Map.
We can now plot this Map and then use the x_lims_pixel and y_lims_pixel to set the range of the axes for which to plot.
Total running time of the script: ( 0 minutes 1.231 seconds)