pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/matplotlib/matplotlib/commit/49b4babfe56329bef8a93078ac41763d6234931a

.css" /> Merge pull request #31170 from anntzer/qki · matplotlib/matplotlib@49b4bab · GitHub
Skip to content

Commit 49b4bab

Browse files
authored
Merge pull request #31170 from anntzer/qki
Cleanup QuiverKey init and deprecate some attributes.
2 parents fb6ca2d + e0b151a commit 49b4bab

File tree

4 files changed

+56
-35
lines changed

4 files changed

+56
-35
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
``kw``, ``fontproperties``, ``labelcolor``, and ``verts`` attributes of ``QuiverKey``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
These attributes are deprecated (note that ``fontproperties``, ``labelcolor``,
4+
or ``verts`` after the first draw had no effect previously). Directly
5+
access the relevant attributes on the sub-artists ``QuiverKey.vector`` and
6+
``QuiverKey.text``, instead.

lib/matplotlib/quiver.py

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -348,47 +348,57 @@ def __init__(self, Q, X, Y, U, label,
348348
self._labelsep_inches = labelsep
349349

350350
self.labelpos = labelpos
351-
self.labelcolor = labelcolor
352-
self.fontproperties = fontproperties or dict()
353-
self.kw = kwargs
351+
self._kw = kwargs # Remove when kw deprecation elapses.
352+
self.vector = mcollections.PolyCollection(
353+
[], **{**self.Q.polykw, **kwargs})
354354
self.text = mtext.Text(
355355
text=label,
356356
horizontalalignment=self.halign[self.labelpos],
357357
verticalalignment=self.valign[self.labelpos],
358-
fontproperties=self.fontproperties)
359-
if self.labelcolor is not None:
360-
self.text.set_color(self.labelcolor)
358+
fontproperties=fontproperties or {})
359+
if labelcolor is not None:
360+
self.text.set_color(labelcolor)
361361
self._dpi_at_last_init = None
362362
self.zorder = zorder if zorder is not None else Q.zorder + 0.1
363363

364+
kw = _api.deprecated("3.11")( # Also remove self._kw when deprecation elapses.
365+
property(lambda self: self._kw))
366+
fontproperties = _api.deprecated(
367+
"3.11", alternative="quiverkey.text.get_fontproperties()")(
368+
property(lambda self: self.text.get_fontproperties()))
369+
labelcolor = _api.deprecated(
370+
"3.11", alternative="quiverkey.text.get_color()")(
371+
property(lambda self: self.text.get_color()))
372+
verts = _api.deprecated(
373+
"3.11", alternative="[p.vertices for p in quiverkey.vector.get_paths()]")(
374+
property(lambda self: [p.vertices for p in self.vector.get_paths()]))
375+
364376
@property
365377
def labelsep(self):
366378
return self._labelsep_inches * self.Q.axes.get_figure(root=True).dpi
367379

368380
def _init(self):
369-
if True: # self._dpi_at_last_init != self.axes.get_figure().dpi
370-
if self.Q._dpi_at_last_init != self.Q.axes.get_figure(root=True).dpi:
371-
self.Q._init()
372-
self._set_transform()
373-
with cbook._setattr_cm(self.Q, pivot=self.pivot[self.labelpos],
374-
# Hack: save and restore the Umask
375-
Umask=ma.nomask):
376-
u = self.U * np.cos(np.radians(self.angle))
377-
v = self.U * np.sin(np.radians(self.angle))
378-
self.verts = self.Q._make_verts([[0., 0.]],
379-
np.array([u]), np.array([v]), 'uv')
380-
kwargs = self.Q.polykw
381-
kwargs.update(self.kw)
382-
self.vector = mcollections.PolyCollection(
383-
self.verts,
384-
offsets=[(self.X, self.Y)],
385-
offset_transform=self.get_transform(),
386-
**kwargs)
387-
if self.color is not None:
388-
self.vector.set_color(self.color)
389-
self.vector.set_transform(self.Q.get_transform())
390-
self.vector.set_figure(self.get_figure())
391-
self._dpi_at_last_init = self.Q.axes.get_figure(root=True).dpi
381+
if False: # self._dpi_at_last_init == self.axes.get_figure().dpi
382+
return
383+
if self.Q._dpi_at_last_init != self.Q.axes.get_figure(root=True).dpi:
384+
self.Q._init()
385+
self._set_transform()
386+
with cbook._setattr_cm(self.Q, pivot=self.pivot[self.labelpos],
387+
# Hack: save and restore the Umask
388+
Umask=ma.nomask):
389+
u = self.U * np.cos(np.radians([self.angle]))
390+
v = self.U * np.sin(np.radians([self.angle]))
391+
verts = self.Q._make_verts([[0., 0.]], u, v, 'uv')
392+
self.vector.set(
393+
verts=verts,
394+
offsets=[(self.X, self.Y)],
395+
offset_transform=self.get_transform(),
396+
transform=self.Q.get_transform(),
397+
figure=self.get_figure(),
398+
)
399+
if self.color is not None:
400+
self.vector.set_color(self.color)
401+
self._dpi_at_last_init = self.Q.axes.get_figure(root=True).dpi
392402

393403
def _text_shift(self):
394404
return {

lib/matplotlib/quiver.pyi

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ class QuiverKey(martist.Artist):
2525
color: ColorType | None
2626
label: str
2727
labelpos: Literal["N", "S", "E", "W"]
28-
labelcolor: ColorType | None
29-
fontproperties: dict[str, Any]
30-
kw: dict[str, Any]
3128
text: Text
3229
zorder: float
3330
def __init__(
@@ -49,6 +46,14 @@ class QuiverKey(martist.Artist):
4946
**kwargs
5047
) -> None: ...
5148
@property
49+
def kw(self) -> dict[str, Any]: ...
50+
@property
51+
def fontproperties(self) -> dict[str, Any]: ...
52+
@property
53+
def labelcolor(self) -> ColorType | None: ...
54+
@property
55+
def verts(self) -> Sequence[ArrayLike]: ...
56+
@property
5257
def labelsep(self) -> float: ...
5358
def set_figure(self, fig: Figure | SubFigure) -> None: ...
5459

lib/matplotlib/tests/test_quiver.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def test_quiverkey_angles():
266266
qk = ax.quiverkey(q, 1, 1, 2, 'Label')
267267
# The arrows are only created when the key is drawn
268268
fig.canvas.draw()
269-
assert len(qk.verts) == 1
269+
assert len(qk.vector.get_paths()) == 1
270270

271271

272272
def test_quiverkey_angles_xy_aitoff():
@@ -295,7 +295,7 @@ def test_quiverkey_angles_xy_aitoff():
295295
qk = ax.quiverkey(q, 0, 0, 1, '1 units')
296296

297297
fig.canvas.draw()
298-
assert len(qk.verts) == 1
298+
assert len(qk.vector.get_paths()) == 1
299299

300300

301301
def test_quiverkey_angles_scale_units_cartesian():
@@ -322,7 +322,7 @@ def test_quiverkey_angles_scale_units_cartesian():
322322
qk = ax.quiverkey(q, 0, 0, 1, '1 units')
323323

324324
fig.canvas.draw()
325-
assert len(qk.verts) == 1
325+
assert len(qk.vector.get_paths()) == 1
326326

327327

328328
def test_quiver_setuvc_numbers():

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy