Skip to content

Automatic labels and titles to plots based on xarray metadata #1412

Open

Description

@weiji14

Description of the desired feature

Originally posted by @leouieda as a comment about xarray integration at https://hackmd.io/@pygmt/SkVmX_20d:

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.

xarray automatic labels and titles

The auto-labels/titles currently comes for free in xarray through the xarray.DataArray.plot.imshow() function. We could inspect the source code at https://github.com/pydata/xarray/blob/v0.19.0/xarray/plot/plot.py#L244 to see how this can be implemented in PyGMT.

Are you willing to help implement and maintain this feature? Long term stuff for PyGMT > v0.6.0

Activity

  1. added
    feature request
    on Aug 4, 2021
  2. added
    good first issue
    help wanted
    on Nov 6, 2021
  3. added this to the 0.7.0 milestone on Nov 6, 2021
  4. modified the milestones: 0.7.0, 0.8.0 on Jun 19, 2022
  5. modified the milestones: 0.8.0, 1.0.0 on Sep 20, 2022
  6. removed
    good first issue
    on Feb 17, 2023
  7. seisman commented on Feb 17, 2023

    @seisman
    Member

    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):
    image

    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()
    

    The image is:
    map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requesthelp wanted

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions