Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit8ddf3ea

Browse files
committed
Adding 2d support to quadmesh set_array
1 parentef9fc20 commit8ddf3ea

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

‎lib/matplotlib/collections.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,8 @@ def update_scalarmappable(self):
782782
"""Update colors from the scalar mappable array, if it is not None."""
783783
ifself._AisNone:
784784
return
785-
ifself._A.ndim>1:
785+
# QuadMesh can map 2d arrays
786+
ifself._A.ndim>1andnotisinstance(self,QuadMesh):
786787
raiseValueError('Collections can only map rank 1 arrays')
787788
ifnotself.check_update("array"):
788789
return
@@ -2071,8 +2072,10 @@ def draw(self, renderer):
20712072
else:
20722073
renderer.draw_quad_mesh(
20732074
gc,transform.frozen(),self._meshWidth,self._meshHeight,
2074-
coordinates,offsets,transOffset,self.get_facecolor(),
2075-
self._antialiased,self.get_edgecolors())
2075+
coordinates,offsets,transOffset,
2076+
# Backends expect flattened rgba arrays (n*m, 4) for fc and ec
2077+
self.get_facecolor().reshape((-1,4)),
2078+
self._antialiased,self.get_edgecolors().reshape((-1,4)))
20762079
gc.restore()
20772080
renderer.close_group(self.__class__.__name__)
20782081
self.stale=False

‎lib/matplotlib/tests/test_collections.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,3 +623,21 @@ def test_collection_set_verts_array():
623623
forap,lpinzip(col_arr._paths,col_list._paths):
624624
assertnp.array_equal(ap._vertices,lp._vertices)
625625
assertnp.array_equal(ap._codes,lp._codes)
626+
627+
628+
deftest_quadmesh_set_array():
629+
x=np.arange(4)
630+
y=np.arange(4)
631+
z=np.arange(9).reshape((3,3))
632+
fig,ax=plt.subplots()
633+
coll=ax.pcolormesh(x,y,np.ones(z.shape))
634+
# Make sure that the collection was able to update the array based on
635+
# 2d input and that it is stored internally as a 1d array
636+
coll.set_array(z)
637+
fig.canvas.draw()
638+
assertnp.array_equal(coll.get_array(),z)
639+
640+
# If someone is already passing a 1d array in, make sure that works too
641+
coll.set_array(np.ones(9))
642+
fig.canvas.draw()
643+
assertnp.array_equal(coll.get_array(),np.ones(9))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp