proplot-dev / proplot

🎨 A succinct matplotlib wrapper for making beautiful, publication-quality graphics
https://proplot.readthedocs.io
MIT License
1.11k stars 102 forks source link

Feature request: xlabel and ylabel for GeoAxes #321

Open syrte opened 2 years ago

syrte commented 2 years ago

Hi, thanks for the great package. I found this package today and got very excited about it. I have skimmed over the document with great enthusiasm. It is really what matplotlib should have become!

I am an astronomer, sometimes I need to plot the stars in the sky coordinate with a certain projection. (This is actually how I found your package :) This task is pretty much the same as plotting a map of the world. So proplot seems very attractive for the task for its concise API (compared with cartopy). However I found a small problem for my usage, the GeoAxes of proplot does not allow one to set xlabel and ylabel (as I have tried and if I understand correctly). I can understand when plotting the map on the earth, everyone knows the axes should be longitude and latitude, so it makes sense to ignore the labels. But in our case, astronomers frequently use different sky coordinates, e.g., based on the sun or the Milky Way location. So it is critical to label the axes that we use.

I am wondering if it is possible to enable setting xlabel and ylabel for GeoAxes. Thanks!

My system:

proplot.__version__, matplotlib.__version__, cartopy.__version__
('0.9.5', '3.4.3', '0.20.2')

BTW, I found that I can play a trick by using the leftlabels and bottomlabels as alternatives of the xlabel and ylabel as a workaround, see the code below. They look just like normal xy labels in the right panel. However, this trick is limited. It does not work well when I have multiple panels. For example, I can not change the order of defining the two subplots, unless I define labels for every panel through this trick.

import numpy as np
import proplot as pplt

fig = pplt.figure(span=False, suptitle='Example')

ax = fig.subplot(121, proj='ortho', proj_kw={'lon_0': 0, 'lat_0': 0})
ax.format(lonlim=(-20, 20), latlim=(-20, 20),
          lonlines=10, latlines=5, labels=True,
          latformatter="simple", lonformatter="simple",
          leftlabels=['dec'],
          bottomlabels=['ra'],
          leftlabels_kw=dict(fontweight='regular', fontsize='medium'),
          bottomlabels_kw=dict(fontweight='regular', fontsize='medium')
          )
ax.scatter(np.random.rand(100) * 15, np.random.rand(100) * 15, s=2)
ax.plot(np.arange(20), s=10)

ax = fig.subplot(122)
ax.format(xlim=(-20, 20), ylim=(-20, 20),
          xlabel='xdata', ylabel='ydata')

image

lukelbd commented 2 years ago

Really appreciate the kind words! Very cool to hear someone from astronomy using this.

I can definitely add xlabel and ylabel as optional GeoAxes.format and PolarAxes.format keywords. Maybe will add this when resolving #79/#199. For now, it looks like you can use matplotlib's native setters to add axis labels:

import proplot as pplt
fig, ax = pplt.subplots(proj='robin')
ax.xaxis.set_visible(True)  # cartopy sets this to False
ax.yaxis.set_visible(True)
ax.xaxis.set_ticks([])
ax.yaxis.set_ticks([])
ax.set_xlabel('very very long xlabel')
ax.set_ylabel('ylabel')

tmp_plot

syrte commented 2 years ago

Ah, I wasn't aware of this part ax.xaxis.set_visible(True). Thanks! The native setters of axis labels work well.