help tweaking maps in sunpy v0.8

56 views
Skip to first unread message

Iain Hannah

unread,
Oct 17, 2017, 10:45:27 AM10/17/17
to SunPy
Hi folks

Need some help getting the sunpy maps looking how I want in v0.8. 

For the code below and its output how do I:
  • Hide the latitude and longitude tick marks and labels (number of degrees on top and right axes)?
  • Hide the "Solar Longitude" and "Solar Latitude" axes (top and right) labels?
  • Hide the Helioprojective longitude and latitude (solar-x and -y) grid (faint white lines)? 
Cheers
Iain



import astropy.units as u
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
from pylab import figure
from astropy.coordinates import SkyCoord
import sunpy.map
from sunpy.data.sample import AIA_171_IMAGE

aiamap
= sunpy.map.Map(AIA_171_IMAGE)

bl
= SkyCoord(-400*u.arcsec, -900*u.arcsec, frame=aiamap.coordinate_frame)
tr
= SkyCoord(800*u.arcsec, 700*u.arcsec, frame=aiamap.coordinate_frame)
ams
= aiamap.submap(bl,tr)

ams
.plot_settings['norm'] = LogNorm(1e2, 1e4)

fig
= plt.figure(figsize=(9, 8))
ax
= plt.subplot(projection=ams)
ams
.plot()
ams
.draw_limb(color='black',linewidth=2,linestyle='dashed')  
ams
.draw_grid(color='blue',linewidth=2,linestyle='dotted')
title_obsdate
='{:.20}'.format('{:%Y-%b-%d %H:%M:%s}'.format(ams.date))

ax
.set_title('AIA 171$\AA$ '+ title_obsdate)
ax
.set_ylabel('y [arcsec]')
ax
.set_xlabel('x [arcsec]')
plt
.colorbar(fraction=0.035, pad=0.03,label='DN')
plt
.show()

Jack Ireland

unread,
Oct 17, 2017, 11:48:18 AM10/17/17
to su...@googlegroups.com
ax.grid(False) will switch off the faint white lines.

As for the other stuff, you want to just have the blue grid, right?

--
You received this message because you are subscribed to the Google Groups "SunPy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sunpy+unsubscribe@googlegroups.com.
To post to this group, send email to su...@googlegroups.com.
Visit this group at https://groups.google.com/group/sunpy.
For more options, visit https://groups.google.com/d/optout.

Iain Hannah

unread,
Oct 17, 2017, 5:09:42 PM10/17/17
to SunPy
Thanks that works.

Yeah, want the blue longitude/latitude grid but none of the extra labelling on the top or right axes. 
To unsubscribe from this group and stop receiving emails from it, send an email to sunpy+un...@googlegroups.com.

Stuart Mumford

unread,
Oct 18, 2017, 10:34:40 AM10/18/17
to su...@googlegroups.com

Hi Iain,

Thanks for the email, it's highlighted that there are a couple of tweaks that should be made to the plotting functions / docs to make it easier to get simpler plots out.

To answer your question you want to setup the heliographic grid manually, so replace the `ams.draw_grid` with the following:

# Manually plot a heliographic overlay.
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')

overlay.grid(color='blue', linewidth=2, linestyle='dashed')

I will add some kind of "no ticks" option to draw_grid to simplfy this in 0.9.

Hope that helps,
Stuart

Jack Ireland

unread,
Oct 18, 2017, 10:42:38 AM10/18/17
to su...@googlegroups.com

I was *just* about to send this along too... thanks Stuart!

Even with no_ticks options in map.draw_grid, this would make the basis of a good example in the Example gallery on how to get fine grained control on the grid properties.

Iain Hannah

unread,
Oct 18, 2017, 10:51:27 AM10/18/17
to SunPy
Thanks, that works, but a no_ticks option would be appreciated.

While I'm being picky about plotting, is there a way to force the axis labels to be integers instead of floats? In my example the major tick unit is 300" so a bit pointless to give it to one decimal place precision. I was trying things like ax.yaxis.set_major_formatter(FormatStrFormatter('%i4')) but that doesn't seem to do anything.

Cheers
Iain

Stuart Mumford

unread,
Oct 18, 2017, 10:56:56 AM10/18/17
to su...@googlegroups.com

Hi,

You can do this using WCSAxes as described here:

http://docs.astropy.org/en/stable/visualization/wcsaxes/ticks_labels_grid.html#tick-label-format

setting the format to 's' should do it:

tx, ty = ax.coords
tx.set_major_formatter('s')
ty.set_major_formatter('s')


Stuart

Iain Hannah

unread,
Oct 18, 2017, 11:28:55 AM10/18/17
to SunPy
Thanks, that works, and a very useful link.
Reply all
Reply to author
Forward
0 new messages