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 dacd3fe

Browse filesBrowse files
committed
Switch transOffset to offset_transform.
Note that most APIs *previously* already accepted *offset_transform* as kwarg, due to the presence of the `set_offset_transform` setter. Prefer that name (shortening it to `offset_trf` for local variables). Backcompat for the old `transOffset` name is kept in most places by introducing a property alias.
1 parent 7443d88 commit dacd3fe
Copy full SHA for dacd3fe

File tree

13 files changed

+114
-113
lines changed
Filter options

13 files changed

+114
-113
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
@@ -45,7 +45,7 @@ def __init__(self, ax, data):
4545
6, sizes=(100,),
4646
facecolors=facecolors,
4747
offsets=self.xys,
48-
transOffset=ax.transData)
48+
offset_transform=ax.transData)
4949

5050
ax.add_collection(self.collection)
5151

‎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
+37-35Lines changed: 37 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_trf = offset_transform
206207

207208
self._path_effects = None
208209
self.update(kwargs)
@@ -219,22 +220,23 @@ 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_trf is None:
224+
self._offset_trf = transforms.IdentityTransform()
225+
elif (not isinstance(self._offset_trf, transforms.Transform)
226+
and hasattr(self._offset_trf, '_as_mpl_transform')):
227+
self._offset_trf = self._offset_trf._as_mpl_transform(self.axes)
228+
return self._offset_trf
228229

229-
def set_offset_transform(self, transOffset):
230+
@_api.rename_parameter("3.6", "transOffset", "offset_transform")
231+
def set_offset_transform(self, offset_transform):
230232
"""
231233
Set the artist offset transform.
232234
233235
Parameters
234236
----------
235-
transOffset : `.Transform`
237+
offset_transform : `.Transform`
236238
"""
237-
self._transOffset = transOffset
239+
self._offset_trf = offset_transform
238240

239241
def get_datalim(self, transData):
240242
# Calculate the data limits and return them as a `.Bbox`.
@@ -254,9 +256,9 @@ def get_datalim(self, transData):
254256
# 3. otherwise return a null Bbox.
255257

256258
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):
259+
offset_trf = self.get_offset_transform()
260+
has_offsets = np.any(self._offsets) # True if any non-zero offsets
261+
if has_offsets and not offset_trf.contains_branch(transData):
260262
# if there are offsets but in some coords other than data,
261263
# then don't use them for autoscaling.
262264
return transforms.Bbox.null()
@@ -284,16 +286,16 @@ def get_datalim(self, transData):
284286
return mpath.get_path_collection_extents(
285287
transform.get_affine() - transData, paths,
286288
self.get_transforms(),
287-
transOffset.transform_non_affine(offsets),
288-
transOffset.get_affine().frozen())
289-
if hasOffsets:
289+
offset_trf.transform_non_affine(offsets),
290+
offset_trf.get_affine().frozen())
291+
if has_offsets:
290292
# this is for collections that have their paths (shapes)
291293
# in physical, axes-relative, or figure-relative units
292294
# (i.e. like scatter). We can't uniquely set limits based on
293295
# those shapes, so we just set the limits based on their
294296
# location.
295297

296-
offsets = (transOffset - transData).transform(offsets)
298+
offsets = (offset_trf - transData).transform(offsets)
297299
# note A-B means A B^{-1}
298300
offsets = np.ma.masked_invalid(offsets)
299301
if not offsets.mask.all():
@@ -311,7 +313,7 @@ def _prepare_points(self):
311313
# Helper for drawing and hit testing.
312314

313315
transform = self.get_transform()
314-
transOffset = self.get_offset_transform()
316+
offset_trf = self.get_offset_transform()
315317
offsets = self._offsets
316318
paths = self.get_paths()
317319

@@ -332,17 +334,17 @@ def _prepare_points(self):
332334
paths = [transform.transform_path_non_affine(path)
333335
for path in paths]
334336
transform = transform.get_affine()
335-
if not transOffset.is_affine:
336-
offsets = transOffset.transform_non_affine(offsets)
337+
if not offset_trf.is_affine:
338+
offsets = offset_trf.transform_non_affine(offsets)
337339
# This might have changed an ndarray into a masked array.
338-
transOffset = transOffset.get_affine()
340+
offset_trf = offset_trf.get_affine()
339341

340342
if isinstance(offsets, np.ma.MaskedArray):
341343
offsets = offsets.filled(np.nan)
342344
# Changing from a masked array to nan-filled ndarray
343345
# is probably most efficient at this point.
344346

345-
return transform, transOffset, offsets, paths
347+
return transform, offset_trf, offsets, paths
346348

347349
@artist.allow_rasterization
348350
def draw(self, renderer):
@@ -352,7 +354,7 @@ def draw(self, renderer):
352354

353355
self.update_scalarmappable()
354356

355-
transform, transOffset, offsets, paths = self._prepare_points()
357+
transform, offset_trf, offsets, paths = self._prepare_points()
356358

357359
gc = renderer.new_gc()
358360
self._set_gc_clip(gc)
@@ -408,11 +410,11 @@ def draw(self, renderer):
408410
gc.set_url(self._urls[0])
409411
renderer.draw_markers(
410412
gc, paths[0], combined_transform.frozen(),
411-
mpath.Path(offsets), transOffset, tuple(facecolors[0]))
413+
mpath.Path(offsets), offset_trf, tuple(facecolors[0]))
412414
else:
413415
renderer.draw_path_collection(
414416
gc, transform.frozen(), paths,
415-
self.get_transforms(), offsets, transOffset,
417+
self.get_transforms(), offsets, offset_trf,
416418
self.get_facecolor(), self.get_edgecolor(),
417419
self._linewidths, self._linestyles,
418420
self._antialiaseds, self._urls,
@@ -459,7 +461,7 @@ def contains(self, mouseevent):
459461
if self.axes:
460462
self.axes._unstale_viewLim()
461463

462-
transform, transOffset, offsets, paths = self._prepare_points()
464+
transform, offset_trf, offsets, paths = self._prepare_points()
463465

464466
# Tests if the point is contained on one of the polygons formed
465467
# by the control points of each of the paths. A point is considered
@@ -469,7 +471,7 @@ def contains(self, mouseevent):
469471
ind = _path.point_in_path_collection(
470472
mouseevent.x, mouseevent.y, pickradius,
471473
transform.frozen(), paths, self.get_transforms(),
472-
offsets, transOffset, pickradius <= 0)
474+
offsets, offset_trf, pickradius <= 0)
473475

474476
return len(ind) > 0, dict(ind=ind)
475477

@@ -1317,7 +1319,7 @@ def __init__(self,
13171319
edgecolors=("black",),
13181320
linewidths=(1,),
13191321
offsets=offsets,
1320-
transOffset=ax.transData,
1322+
offset_transform=ax.transData,
13211323
)
13221324
"""
13231325
super().__init__(**kwargs)
@@ -2149,7 +2151,7 @@ def draw(self, renderer):
21492151
return
21502152
renderer.open_group(self.__class__.__name__, self.get_gid())
21512153
transform = self.get_transform()
2152-
transOffset = self.get_offset_transform()
2154+
offset_trf = self.get_offset_transform()
21532155
offsets = self._offsets
21542156

21552157
if self.have_units():
@@ -2168,9 +2170,9 @@ def draw(self, renderer):
21682170
else:
21692171
coordinates = self._coordinates
21702172

2171-
if not transOffset.is_affine:
2172-
offsets = transOffset.transform_non_affine(offsets)
2173-
transOffset = transOffset.get_affine()
2173+
if not offset_trf.is_affine:
2174+
offsets = offset_trf.transform_non_affine(offsets)
2175+
offset_trf = offset_trf.get_affine()
21742176

21752177
gc = renderer.new_gc()
21762178
gc.set_snap(self.get_snap())
@@ -2185,7 +2187,7 @@ def draw(self, renderer):
21852187
renderer.draw_quad_mesh(
21862188
gc, transform.frozen(),
21872189
coordinates.shape[1] - 1, coordinates.shape[0] - 1,
2188-
coordinates, offsets, transOffset,
2190+
coordinates, offsets, offset_trf,
21892191
# Backends expect flattened rgba arrays (n*m, 4) for fc and ec
21902192
self.get_facecolor().reshape((-1, 4)),
21912193
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.