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

Commitca4ddac

Browse files
committed
Don't reshape offsets into the correct shape.
(Instead let invalid entries error.)
1 parenta4bd3ce commitca4ddac

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

‎lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4023,7 +4023,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
40234023
edgecolors='face'
40244024
linewidths=rcParams['lines.linewidth']
40254025

4026-
offsets=np.dstack((x,y))
4026+
offsets=np.column_stack([x,y])
40274027

40284028
collection=mcoll.PathCollection(
40294029
(path,),scales,

‎lib/matplotlib/collections.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def __init__(self,
145145
self._uniform_offsets=None
146146
self._offsets=np.array([[0,0]],float)
147147
ifoffsetsisnotNone:
148-
offsets=np.asanyarray(offsets).reshape((-1,2))
148+
offsets=np.asanyarray(offsets,float)
149149
iftransOffsetisnotNone:
150150
self._offsets=offsets
151151
self._transOffset=transOffset
@@ -210,7 +210,6 @@ def get_datalim(self, transData):
210210
offsets=transOffset.transform_non_affine(offsets)
211211
transOffset=transOffset.get_affine()
212212

213-
offsets=np.asanyarray(offsets,float).reshape((-1,2))
214213
ifisinstance(offsets,np.ma.MaskedArray):
215214
offsets=offsets.filled(np.nan)
216215
# get_path_collection_extents handles nan but not masked arrays
@@ -244,14 +243,12 @@ def _prepare_points(self):
244243
xs,ys=vertices[:,0],vertices[:,1]
245244
xs=self.convert_xunits(xs)
246245
ys=self.convert_yunits(ys)
247-
paths.append(mpath.Path(list(zip(xs,ys)),path.codes))
246+
paths.append(mpath.Path(np.column_stack([xs,ys]),path.codes))
248247

249248
ifoffsets.size>0:
250249
xs=self.convert_xunits(offsets[:,0])
251250
ys=self.convert_yunits(offsets[:,1])
252-
offsets=list(zip(xs,ys))
253-
254-
offsets=np.asanyarray(offsets,float).reshape((-1,2))
251+
offsets=np.column_stack([xs,ys])
255252

256253
ifnottransform.is_affine:
257254
paths= [transform.transform_path_non_affine(path)
@@ -431,7 +428,7 @@ def set_offsets(self, offsets):
431428
432429
ACCEPTS: float or sequence of floats
433430
"""
434-
offsets=np.asanyarray(offsets,float).reshape((-1,2))
431+
offsets=np.asanyarray(offsets,float)
435432
#This decision is based on how they are initialized above
436433
ifself._uniform_offsetsisNone:
437434
self._offsets=offsets
@@ -1881,17 +1878,12 @@ def draw(self, renderer):
18811878
iflen(self._offsets):
18821879
xs=self.convert_xunits(self._offsets[:,0])
18831880
ys=self.convert_yunits(self._offsets[:,1])
1884-
offsets=list(zip(xs,ys))
1885-
1886-
offsets=np.asarray(offsets,float).reshape((-1,2))
1881+
offsets=np.column_stack([xs,ys])
18871882

18881883
self.update_scalarmappable()
18891884

18901885
ifnottransform.is_affine:
1891-
coordinates=self._coordinates.reshape(
1892-
(self._coordinates.shape[0]*
1893-
self._coordinates.shape[1],
1894-
2))
1886+
coordinates=self._coordinates.reshape((-1,2))
18951887
coordinates=transform.transform(coordinates)
18961888
coordinates=coordinates.reshape(self._coordinates.shape)
18971889
transform=transforms.IdentityTransform()

‎lib/matplotlib/tests/test_collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def test_regularpolycollection_rotate():
538538
forxy,alphainzip(xy_points,rotations):
539539
col=mcollections.RegularPolyCollection(
540540
4,sizes=(100,),rotation=alpha,
541-
offsets=xy,transOffset=ax.transData)
541+
offsets=[xy],transOffset=ax.transData)
542542
ax.add_collection(col,autolim=True)
543543
ax.autoscale_view()
544544

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp