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 5de27aa

Browse filesBrowse files
authored
Merge pull request #21965 from anntzer/ot
2 parents 5601f5a + c25cf96 commit 5de27aa
Copy full SHA for 5de27aa

File tree

13 files changed

+116
-114
lines changed
Filter options

13 files changed

+116
-114
lines changed
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``transOffset`` parameter name
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The ``transOffset`` parameter of `.Collection.set_offset_transform` and the
4+
various ``create_collection`` methods of legend handlers has been renamed to
5+
``offset_transform`` (consistently with the property name).

‎examples/event_handling/lasso_demo.py

Copy file name to clipboardExpand all lines: examples/event_handling/lasso_demo.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self, ax, data):
5353
6, sizes=(100,),
5454
facecolors=facecolors,
5555
offsets=self.xys,
56-
transOffset=ax.transData)
56+
offset_transform=ax.transData)
5757

5858
ax.add_collection(self.collection)
5959

‎examples/shapes_and_collections/collections.py

Copy file name to clipboardExpand all lines: examples/shapes_and_collections/collections.py
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
66
For the first two subplots, we will use spirals. Their size will be set in
77
plot units, not data units. Their positions will be set in data units by using
8-
the *offsets* and *transOffset* keyword arguments of the `.LineCollection` and
9-
`.PolyCollection`.
8+
the *offsets* and *offset_transform* keyword arguments of the `.LineCollection`
9+
and `.PolyCollection`.
1010
1111
The third subplot will make regular polygons, with the same
1212
type of scaling and positioning as in the first two.
@@ -46,8 +46,8 @@
4646
hspace=0.3, wspace=0.3)
4747

4848

49-
col = collections.LineCollection([spiral], offsets=xyo,
50-
transOffset=ax1.transData)
49+
col = collections.LineCollection(
50+
[spiral], offsets=xyo, offset_transform=ax1.transData)
5151
trans = fig.dpi_scale_trans + transforms.Affine2D().scale(1.0/72.0)
5252
col.set_transform(trans) # the points to pixels transform
5353
# Note: the first argument to the collection initializer
@@ -71,8 +71,8 @@
7171

7272

7373
# The same data as above, but fill the curves.
74-
col = collections.PolyCollection([spiral], offsets=xyo,
75-
transOffset=ax2.transData)
74+
col = collections.PolyCollection(
75+
[spiral], offsets=xyo, offset_transform=ax2.transData)
7676
trans = transforms.Affine2D().scale(fig.dpi/72.0)
7777
col.set_transform(trans) # the points to pixels transform
7878
ax2.add_collection(col, autolim=True)
@@ -85,7 +85,7 @@
8585
# 7-sided regular polygons
8686

8787
col = collections.RegularPolyCollection(
88-
7, sizes=np.abs(xx) * 10.0, offsets=xyo, transOffset=ax3.transData)
88+
7, sizes=np.abs(xx) * 10.0, offsets=xyo, offset_transform=ax3.transData)
8989
trans = transforms.Affine2D().scale(fig.dpi / 72.0)
9090
col.set_transform(trans) # the points to pixels transform
9191
ax3.add_collection(col, autolim=True)

‎examples/shapes_and_collections/ellipse_collection.py

Copy file name to clipboardExpand all lines: examples/shapes_and_collections/ellipse_collection.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
a `~.collections.EllipseCollection` or `~.collections.PathCollection`, the use
88
of an `~.collections.EllipseCollection` allows for much shorter code.
99
"""
10+
1011
import matplotlib.pyplot as plt
1112
import numpy as np
1213
from matplotlib.collections import EllipseCollection
@@ -25,7 +26,7 @@
2526
fig, ax = plt.subplots()
2627

2728
ec = EllipseCollection(ww, hh, aa, units='x', offsets=XY,
28-
transOffset=ax.transData)
29+
offset_transform=ax.transData)
2930
ec.set_array((X + Y).ravel())
3031
ax.add_collection(ec)
3132
ax.autoscale_view()

‎examples/specialty_plots/mri_with_eeg.py

Copy file name to clipboardExpand all lines: examples/specialty_plots/mri_with_eeg.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
offsets = np.zeros((n_rows, 2), dtype=float)
6565
offsets[:, 1] = ticklocs
6666

67-
lines = LineCollection(segs, offsets=offsets, transOffset=None)
67+
lines = LineCollection(segs, offsets=offsets, offset_transform=None)
6868
ax2.add_collection(lines)
6969

7070
# Set the yticks to use axes coordinates on the y axis

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+11-10Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4463,14 +4463,14 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
44634463
offsets = np.ma.column_stack([x, y])
44644464

44654465
collection = mcoll.PathCollection(
4466-
(path,), scales,
4467-
facecolors=colors,
4468-
edgecolors=edgecolors,
4469-
linewidths=linewidths,
4470-
offsets=offsets,
4471-
transOffset=kwargs.pop('transform', self.transData),
4472-
alpha=alpha
4473-
)
4466+
(path,), scales,
4467+
facecolors=colors,
4468+
edgecolors=edgecolors,
4469+
linewidths=linewidths,
4470+
offsets=offsets,
4471+
offset_transform=kwargs.pop('transform', self.transData),
4472+
alpha=alpha,
4473+
)
44744474
collection.set_transform(mtransforms.IdentityTransform())
44754475
if colors is None:
44764476
collection.set_array(c)
@@ -4796,8 +4796,9 @@ def reduce_C_function(C: array) -> float
47964796
edgecolors=edgecolors,
47974797
linewidths=linewidths,
47984798
offsets=offsets,
4799-
transOffset=mtransforms.AffineDeltaTransform(self.transData),
4800-
)
4799+
offset_transform=mtransforms.AffineDeltaTransform(
4800+
self.transData),
4801+
)
48014802

48024803
# Set normalizer if bins is 'log'
48034804
if bins == 'log':

‎lib/matplotlib/collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/collections.py
+38-35Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"facecolor": ["facecolors", "fc"],
3131
"linestyle": ["linestyles", "dashes", "ls"],
3232
"linewidth": ["linewidths", "lw"],
33+
"offset_transform": ["transOffset"],
3334
})
3435
class Collection(artist.Artist, cm.ScalarMappable):
3536
r"""
@@ -84,7 +85,7 @@ def __init__(self,
8485
joinstyle=None,
8586
antialiaseds=None,
8687
offsets=None,
87-
transOffset=None,
88+
offset_transform=None,
8889
norm=None, # optional for ScalarMappable
8990
cmap=None, # ditto
9091
pickradius=5.0,
@@ -127,7 +128,7 @@ def __init__(self,
127128
A vector by which to translate each patch after rendering (default
128129
is no translation). The translation is performed in screen (pixel)
129130
coordinates (i.e. after the Artist's transform is applied).
130-
transOffset : `~.transforms.Transform`, default: `.IdentityTransform`
131+
offset_transform : `~.Transform`, default: `.IdentityTransform`
131132
A single transform which will be applied to each *offsets* vector
132133
before it is used.
133134
norm : `~.colors.Normalize`, optional
@@ -202,7 +203,7 @@ def __init__(self,
202203
offsets = offsets[None, :]
203204
self._offsets = offsets
204205

205-
self._transOffset = transOffset
206+
self._offset_transform = offset_transform
206207

207208
self._path_effects = None
208209
self.update(kwargs)
@@ -219,22 +220,24 @@ def get_transforms(self):
219220

220221
def get_offset_transform(self):
221222
"""Return the `.Transform` instance used by this artist offset."""
222-
if self._transOffset is None:
223-
self._transOffset = transforms.IdentityTransform()
224-
elif (not isinstance(self._transOffset, transforms.Transform)
225-
and hasattr(self._transOffset, '_as_mpl_transform')):
226-
self._transOffset = self._transOffset._as_mpl_transform(self.axes)
227-
return self._transOffset
223+
if self._offset_transform is None:
224+
self._offset_transform = transforms.IdentityTransform()
225+
elif (not isinstance(self._offset_transform, transforms.Transform)
226+
and hasattr(self._offset_transform, '_as_mpl_transform')):
227+
self._offset_transform = \
228+
self._offset_transform._as_mpl_transform(self.axes)
229+
return self._offset_transform
228230

229-
def set_offset_transform(self, transOffset):
231+
@_api.rename_parameter("3.6", "transOffset", "offset_transform")
232+
def set_offset_transform(self, offset_transform):
230233
"""
231234
Set the artist offset transform.
232235
233236
Parameters
234237
----------
235-
transOffset : `.Transform`
238+
offset_transform : `.Transform`
236239
"""
237-
self._transOffset = transOffset
240+
self._offset_transform = offset_transform
238241

239242
def get_datalim(self, transData):
240243
# Calculate the data limits and return them as a `.Bbox`.
@@ -254,9 +257,9 @@ def get_datalim(self, transData):
254257
# 3. otherwise return a null Bbox.
255258

256259
transform = self.get_transform()
257-
transOffset = self.get_offset_transform()
258-
hasOffsets = np.any(self._offsets) # True if any non-zero offsets
259-
if hasOffsets and not transOffset.contains_branch(transData):
260+
offset_trf = self.get_offset_transform()
261+
has_offsets = np.any(self._offsets) # True if any non-zero offsets
262+
if has_offsets and not offset_trf.contains_branch(transData):
260263
# if there are offsets but in some coords other than data,
261264
# then don't use them for autoscaling.
262265
return transforms.Bbox.null()
@@ -284,16 +287,16 @@ def get_datalim(self, transData):
284287
return mpath.get_path_collection_extents(
285288
transform.get_affine() - transData, paths,
286289
self.get_transforms(),
287-
transOffset.transform_non_affine(offsets),
288-
transOffset.get_affine().frozen())
289-
if hasOffsets:
290+
offset_trf.transform_non_affine(offsets),
291+
offset_trf.get_affine().frozen())
292+
if has_offsets:
290293
# this is for collections that have their paths (shapes)
291294
# in physical, axes-relative, or figure-relative units
292295
# (i.e. like scatter). We can't uniquely set limits based on
293296
# those shapes, so we just set the limits based on their
294297
# location.
295298

296-
offsets = (transOffset - transData).transform(offsets)
299+
offsets = (offset_trf - transData).transform(offsets)
297300
# note A-B means A B^{-1}
298301
offsets = np.ma.masked_invalid(offsets)
299302
if not offsets.mask.all():
@@ -311,7 +314,7 @@ def _prepare_points(self):
311314
# Helper for drawing and hit testing.
312315

313316
transform = self.get_transform()
314-
transOffset = self.get_offset_transform()
317+
offset_trf = self.get_offset_transform()
315318
offsets = self._offsets
316319
paths = self.get_paths()
317320

@@ -332,17 +335,17 @@ def _prepare_points(self):
332335
paths = [transform.transform_path_non_affine(path)
333336
for path in paths]
334337
transform = transform.get_affine()
335-
if not transOffset.is_affine:
336-
offsets = transOffset.transform_non_affine(offsets)
338+
if not offset_trf.is_affine:
339+
offsets = offset_trf.transform_non_affine(offsets)
337340
# This might have changed an ndarray into a masked array.
338-
transOffset = transOffset.get_affine()
341+
offset_trf = offset_trf.get_affine()
339342

340343
if isinstance(offsets, np.ma.MaskedArray):
341344
offsets = offsets.filled(np.nan)
342345
# Changing from a masked array to nan-filled ndarray
343346
# is probably most efficient at this point.
344347

345-
return transform, transOffset, offsets, paths
348+
return transform, offset_trf, offsets, paths
346349

347350
@artist.allow_rasterization
348351
def draw(self, renderer):
@@ -352,7 +355,7 @@ def draw(self, renderer):
352355

353356
self.update_scalarmappable()
354357

355-
transform, transOffset, offsets, paths = self._prepare_points()
358+
transform, offset_trf, offsets, paths = self._prepare_points()
356359

357360
gc = renderer.new_gc()
358361
self._set_gc_clip(gc)
@@ -408,11 +411,11 @@ def draw(self, renderer):
408411
gc.set_url(self._urls[0])
409412
renderer.draw_markers(
410413
gc, paths[0], combined_transform.frozen(),
411-
mpath.Path(offsets), transOffset, tuple(facecolors[0]))
414+
mpath.Path(offsets), offset_trf, tuple(facecolors[0]))
412415
else:
413416
renderer.draw_path_collection(
414417
gc, transform.frozen(), paths,
415-
self.get_transforms(), offsets, transOffset,
418+
self.get_transforms(), offsets, offset_trf,
416419
self.get_facecolor(), self.get_edgecolor(),
417420
self._linewidths, self._linestyles,
418421
self._antialiaseds, self._urls,
@@ -459,7 +462,7 @@ def contains(self, mouseevent):
459462
if self.axes:
460463
self.axes._unstale_viewLim()
461464

462-
transform, transOffset, offsets, paths = self._prepare_points()
465+
transform, offset_trf, offsets, paths = self._prepare_points()
463466

464467
# Tests if the point is contained on one of the polygons formed
465468
# by the control points of each of the paths. A point is considered
@@ -469,7 +472,7 @@ def contains(self, mouseevent):
469472
ind = _path.point_in_path_collection(
470473
mouseevent.x, mouseevent.y, pickradius,
471474
transform.frozen(), paths, self.get_transforms(),
472-
offsets, transOffset, pickradius <= 0)
475+
offsets, offset_trf, pickradius <= 0)
473476

474477
return len(ind) > 0, dict(ind=ind)
475478

@@ -1317,7 +1320,7 @@ def __init__(self,
13171320
edgecolors=("black",),
13181321
linewidths=(1,),
13191322
offsets=offsets,
1320-
transOffset=ax.transData,
1323+
offset_transform=ax.transData,
13211324
)
13221325
"""
13231326
super().__init__(**kwargs)
@@ -2150,7 +2153,7 @@ def draw(self, renderer):
21502153
return
21512154
renderer.open_group(self.__class__.__name__, self.get_gid())
21522155
transform = self.get_transform()
2153-
transOffset = self.get_offset_transform()
2156+
offset_trf = self.get_offset_transform()
21542157
offsets = self._offsets
21552158

21562159
if self.have_units():
@@ -2169,9 +2172,9 @@ def draw(self, renderer):
21692172
else:
21702173
coordinates = self._coordinates
21712174

2172-
if not transOffset.is_affine:
2173-
offsets = transOffset.transform_non_affine(offsets)
2174-
transOffset = transOffset.get_affine()
2175+
if not offset_trf.is_affine:
2176+
offsets = offset_trf.transform_non_affine(offsets)
2177+
offset_trf = offset_trf.get_affine()
21752178

21762179
gc = renderer.new_gc()
21772180
gc.set_snap(self.get_snap())
@@ -2186,7 +2189,7 @@ def draw(self, renderer):
21862189
renderer.draw_quad_mesh(
21872190
gc, transform.frozen(),
21882191
coordinates.shape[1] - 1, coordinates.shape[0] - 1,
2189-
coordinates, offsets, transOffset,
2192+
coordinates, offsets, offset_trf,
21902193
# Backends expect flattened rgba arrays (n*m, 4) for fc and ec
21912194
self.get_facecolor().reshape((-1, 4)),
21922195
self._antialiased, self.get_edgecolors().reshape((-1, 4)))

‎lib/matplotlib/legend.py

Copy file name to clipboardExpand all lines: lib/matplotlib/legend.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,8 @@ def _auto_legend_data(self):
829829
bboxes.append(
830830
artist.get_path().get_extents(artist.get_transform()))
831831
elif isinstance(artist, Collection):
832-
_, transOffset, hoffsets, _ = artist._prepare_points()
833-
for offset in transOffset.transform(hoffsets):
832+
_, offset_trf, hoffsets, _ = artist._prepare_points()
833+
for offset in offset_trf.transform(hoffsets):
834834
offsets.append(offset)
835835
return bboxes, lines, offsets
836836

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.