Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9091ba9

Browse filesBrowse files
authored
Merge pull request #18472 from greglucas/quadmesh_get_xydata
ENH: Adding a get_coordinates() method to Quadmesh collections
2 parents cf31ef0 + 453abb1 commit 9091ba9
Copy full SHA for 9091ba9

File tree

Expand file treeCollapse file tree

2 files changed

+22
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-0
lines changed

‎lib/matplotlib/collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/collections.py
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,16 @@ def set_paths(self):
20452045
def get_datalim(self, transData):
20462046
return (self.get_transform() - transData).transform_bbox(self._bbox)
20472047

2048+
def get_coordinates(self):
2049+
"""
2050+
Return the vertices of the mesh as an (M+1, N+1, 2) array.
2051+
2052+
M, N are the number of quadrilaterals in the rows / columns of the
2053+
mesh, corresponding to (M+1, N+1) vertices.
2054+
The last dimension specifies the components (x, y).
2055+
"""
2056+
return self._coordinates
2057+
20482058
@staticmethod
20492059
@_api.deprecated("3.5", alternative="QuadMesh(coordinates).get_paths()")
20502060
def convert_mesh_to_paths(meshWidth, meshHeight, coordinates):

‎lib/matplotlib/tests/test_collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_collections.py
+12Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.