basemap
basemap copied to clipboard
Celestial meridian labels incorrect for eck4 projection
I am testing the following eck4 meridian labeling example:
def label_bug(celestial=True, lon_0=65):
m = Basemap(projection='eck4', lon_0=lon_0, resolution=None, celestial=celestial)
m.drawmeridians([lon_0, lon_0 + 60], labels=[0,0,1,0], labelstyle='+/-')
m.drawmapboundary()
With normal coordinates, the labels appear where I expect them:
label_bug(celestial=False)
When celestial is True, the meridians are correctly flipped, but the labels no longer match their positions:
label_bug(celestial=True)
If anyone knows a workaround until this is fixed, please let me know. Thanks!
I've noticed the same problem (but probably much less impactful) problem with the ortho
projection center on lat_0 = -90
(this maybe the only centering positions where ortho
allows meridians to be labeled).
def label_bug(celestial=True, lon_0=65, lat_0=-90):
m = Basemap(projection='ortho', lon_0=lon_0, lat_0=lat_0, resolution=None, celes\
tial=celestial)
m.drawmeridians([lon_0, lon_0 + 60], labels=[0,0,1,0], labelstyle='+/-')
m.drawmapboundary()
label_bug(celestial=False)
label_bug(celestial=True)
I ended up hacking my way around this by using custom ticklabels as described here. Of course, this hack only works if your meridians wrap all the way around the celestial sphere at regular intervals and all you need to do is flip the sign of the longitude.
def lon2str(deg):
deg -= 360. * (deg >= 180)
if (np.abs(deg) == 0) or (np.abs(deg) == 180):
return r"%d${}^{\circ}$"%(-1*deg)
else:
return r"%+d${}^{\circ}$"%(-1*deg)
def hack_labels(celestial=True, lon_0=0, lat_0=-90):
m = Basemap(projection='ortho', lon_0=lon_0, lat_0=lat_0, celestial=celestial)
ra, dec = 100.,-60.
proj = m(ra, dec)
m.scatter(*proj, color='gold', edgecolor='black', marker='*', s=100)
meridians = np.arange(0.,360.,60.)
m.drawmeridians(meridians, labels=[1,1,1,1], labelstyle='+/-',
fmt=lon2str if celestial else '%g')
m.drawmapboundary()
hack_labels(False)
hack_labels(True)