Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 86c6e75

Browse files
committed
ENH: Adding a get_coordinates() method to Quadmesh
This returns the coordinates used to create the Quadmesh collection.
1 parent 185a298 commit 86c6e75

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/matplotlib/collections.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,15 @@ def set_paths(self):
19841984
def get_datalim(self, transData):
19851985
return (self.get_transform() - transData).transform_bbox(self._bbox)
19861986

1987+
def get_coordinates(self):
1988+
"""
1989+
Return the vertices of the mesh as an (M, N, 2) array.
1990+
1991+
M, N are the number of rows / columns in the mesh.
1992+
The last dimension specifies the components (x, y).
1993+
"""
1994+
return self._coordinates
1995+
19871996
@staticmethod
19881997
def convert_mesh_to_paths(meshWidth, meshHeight, coordinates):
19891998
"""

lib/matplotlib/tests/test_collections.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,18 @@ def test_singleton_autolim():
714714
np.testing.assert_allclose(ax.get_xlim(), [-0.06, 0.06])
715715

716716

717+
def test_quadmesh_get_coordinates():
718+
x = [0, 1, 2]
719+
y = [2, 4, 6]
720+
z = np.ones(shape=(2, 2))
721+
xx, yy = np.meshgrid(x, y)
722+
coll = plt.pcolormesh(xx, yy, z)
723+
724+
# shape (3, 3, 2)
725+
coords = np.stack([xx.T, yy.T]).T
726+
assert_array_equal(coll.get_coordinates(), coords)
727+
728+
717729
def test_quadmesh_set_array():
718730
x = np.arange(4)
719731
y = np.arange(4)

0 commit comments

Comments
 (0)