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

Skip to content

Commit f52bbc1

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

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
@@ -2048,6 +2048,15 @@ def set_paths(self):
20482048
def get_datalim(self, transData):
20492049
return (self.get_transform() - transData).transform_bbox(self._bbox)
20502050

2051+
def get_coordinates(self):
2052+
"""
2053+
Return the vertices of the mesh as an (M, N, 2) array.
2054+
2055+
M, N are the number of rows / columns in the mesh.
2056+
The last dimension specifies the components (x, y).
2057+
"""
2058+
return self._coordinates
2059+
20512060
@staticmethod
20522061
def convert_mesh_to_paths(meshWidth, meshHeight, coordinates):
20532062
"""

lib/matplotlib/tests/test_collections.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,18 @@ def test_quadmesh_deprecated_positional(fig_test, fig_ref):
786786
ax.add_collection(qmesh)
787787

788788

789+
def test_quadmesh_get_coordinates():
790+
x = [0, 1, 2]
791+
y = [2, 4, 6]
792+
z = np.ones(shape=(2, 2))
793+
xx, yy = np.meshgrid(x, y)
794+
coll = plt.pcolormesh(xx, yy, z)
795+
796+
# shape (3, 3, 2)
797+
coords = np.stack([xx.T, yy.T]).T
798+
assert_array_equal(coll.get_coordinates(), coords)
799+
800+
789801
def test_quadmesh_set_array():
790802
x = np.arange(4)
791803
y = np.arange(4)

0 commit comments

Comments
 (0)