Skip to content

How to get Quadmesh coordinates #18399

Closed

Description

@greglucas

Describe the issue

Summary

Right now, the coordinates of a Quadmesh, returned from pcolormesh, are not available to the end-user. They are stored internally in the coordinates attribute. This is an issue for Cartopy, when we need to know where the MPL calculated coordinates are located to know whether we should mask some cells for users.

Proposed fix

Add a .get_coordinates() method that returns the private attribute to Quadmesh. This would be minimally invasive, and only ensures that Cartopy isn't relying on a private attribute.

Related to #18317, and my proposed fix in SciTools/cartopy#1646 that relies on the private attribute.

Activity

  1. dopplershift commented on Sep 10, 2020

    @dopplershift
    Contributor

    Should this instead be get_xydata() to mirror the API name on Line2D?

  2. greglucas commented on Sep 11, 2020

    @greglucas
    ContributorAuthor

    That would be fine with me. I only went with coordinates because that is what it is called internally :)

    The other question is what we should return _coordinates is internally stored as shape (nx+1, ny+1, 2). That would be my preference, but there are a lot of legacy raveled data too so I could see [(nx+1)*(ny+1), 2] or similar forms.

  3. jklymak commented on Sep 11, 2020

    @jklymak
    Member

    I'd return as x,y and x and y have shape (nx+1, ny+1).

  4. greglucas commented on Sep 11, 2020

    @greglucas
    ContributorAuthor

    get_xydata returns (N, 2) apparently:

    def get_xydata(self):
    """
    Return the *xy* data as a Nx2 numpy array.
    """
    if self._invalidy or self._invalidx:
    self.recache()
    return self._xy

    Quadmesh get_array() returns a flattened array (nx*ny, )

    Too many options :)

  5. added
    API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …
    on Sep 11, 2020
  6. greglucas commented on Sep 14, 2020

    @greglucas
    ContributorAuthor

    I just opened up #18472 with the basic implementation. I figured we can continue the discussion about the API under the review over there.

  7. added this to the v3.5.0 milestone on May 26, 2021
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

    API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …Maintenance

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions