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

Skip to content

Commit b5c5b9b

Browse files
committed
ENH: Adding a get_coordinates() method to Quadmesh
This returns the coordinates used to create the Quadmesh collection.
1 parent 3bf56aa commit b5c5b9b

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
@@ -2019,6 +2019,15 @@ def set_paths(self):
20192019
def get_datalim(self, transData):
20202020
return (self.get_transform() - transData).transform_bbox(self._bbox)
20212021

2022+
def get_coordinates(self):
2023+
"""
2024+
Return the x and y vertices of the mesh.
2025+
2026+
The shape of the returned coordinates is
2027+
(*meshWidth* + 1, *meshHeight* + 1, 2).
2028+
"""
2029+
return self._coordinates
2030+
20222031
@staticmethod
20232032
def convert_mesh_to_paths(meshWidth, meshHeight, coordinates):
20242033
"""

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_xydata():
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_xydata(), coords)
727+
728+
717729
def test_quadmesh_set_array():
718730
x = np.arange(4)
719731
y = np.arange(4)

0 commit comments

Comments
 (0)