You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Automatic labels and titles to plots based on xarray metadata #1412
Any thoughts on better integration with xarray? Dataset objects can have rich metadata (coordinate names, units, projections, etc) that could be leveraged to automatically add labels and titles to plots. Their plotting backend does that with matplotlib and it's very convenient.
My interpretation of this 'feature request' is that grdimage could automatically add x-axis and y-axis labels/annotations to the plot, and include a title about the z-variable name (without the user setting it explicitly). Something based on pydata/xarray#519.
My interpretation of this 'feature request' is that grdimage could automatically add x-axis and y-axis labels/annotations to the plot, and include a title about the z-variable name (without the user setting it explicitly).
The idea sounds interesting, but I think it's challenging to implement it in PyGMT.
The main problem is, PyGMT is "stateless". When calling grdimage, we don't know if users have already added labels/annotations/titles by calling basemap. Even if PyGMT is "stateful", we also don't know if users want to add labels/annotations/titles themselves later.
However, I find the automatic labels/annotations/titles feature is still very appealing when users want to quickly view a DataArray.
In #2372, I've added a simple imshow() method to the GMTDataArrayAccessor class. With the new method, now it's possible to view a DataArray using a single line of code:
Here is an example using the feature implemented in PR #2372:
from pygmt.datasets import load_earth_relief
grid = load_earth_relief()
grid.gmt.imshow()
Currently, it shows an image like this (which definitely can be greatly improved):
For comparison, to view a DataArray in matplotlib:
from pygmt.datasets import load_earth_relief
import matplotlib.pyplot as plt
grid = load_earth_relief()
grid.plot()
plt.show()
Activity
seisman commentedon Feb 17, 2023
The idea sounds interesting, but I think it's challenging to implement it in PyGMT.
The main problem is, PyGMT is "stateless". When calling
grdimage, we don't know if users have already added labels/annotations/titles by callingbasemap. Even if PyGMT is "stateful", we also don't know if users want to add labels/annotations/titles themselves later.However, I find the automatic labels/annotations/titles feature is still very appealing when users want to quickly view a DataArray.
In #2372, I've added a simple
imshow()method to the GMTDataArrayAccessor class. With the new method, now it's possible to view a DataArray using a single line of code:Here is an example using the feature implemented in PR #2372:
Currently, it shows an image like this (which definitely can be greatly improved):

For comparison, to view a DataArray in matplotlib:
The image is:
