Skip to content

Commit 16c67c8

Browse files
committed
Small cleanups to QuiverKey.
- Text already calls FontProperties._from_any on anything passed as fontproperties; no need to do it ourselves again. - Group together x and y shifts for text positioning.
1 parent 705d250 commit 16c67c8

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

lib/matplotlib/quiver.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import numpy as np
2020
from numpy import ma
2121

22-
from matplotlib import _api, cbook, _docstring, font_manager
22+
from matplotlib import _api, cbook, _docstring
2323
import matplotlib.artist as martist
2424
import matplotlib.collections as mcollections
2525
from matplotlib.patches import CirclePolygon
@@ -303,13 +303,11 @@ def __init__(self, Q, X, Y, U, label,
303303
self.labelcolor = labelcolor
304304
self.fontproperties = fontproperties or dict()
305305
self.kw = kwargs
306-
_fp = self.fontproperties
307306
self.text = mtext.Text(
308307
text=label,
309308
horizontalalignment=self.halign[self.labelpos],
310309
verticalalignment=self.valign[self.labelpos],
311-
fontproperties=font_manager.FontProperties._from_any(_fp))
312-
310+
fontproperties=self.fontproperties)
313311
if self.labelcolor is not None:
314312
self.text.set_color(self.labelcolor)
315313
self._dpi_at_last_init = None
@@ -346,29 +344,20 @@ def _init(self):
346344
self.vector.set_figure(self.get_figure())
347345
self._dpi_at_last_init = self.Q.axes.figure.dpi
348346

349-
def _text_x(self, x):
350-
if self.labelpos == 'E':
351-
return x + self.labelsep
352-
elif self.labelpos == 'W':
353-
return x - self.labelsep
354-
else:
355-
return x
356-
357-
def _text_y(self, y):
358-
if self.labelpos == 'N':
359-
return y + self.labelsep
360-
elif self.labelpos == 'S':
361-
return y - self.labelsep
362-
else:
363-
return y
347+
def _text_shift(self):
348+
return {
349+
"N": (0, +self.labelsep),
350+
"S": (0, -self.labelsep),
351+
"E": (+self.labelsep, 0),
352+
"W": (-self.labelsep, 0),
353+
}[self.labelpos]
364354

365355
@martist.allow_rasterization
366356
def draw(self, renderer):
367357
self._init()
368358
self.vector.draw(renderer)
369-
x, y = self.get_transform().transform((self.X, self.Y))
370-
self.text.set_x(self._text_x(x))
371-
self.text.set_y(self._text_y(y))
359+
pos = self.get_transform().transform((self.X, self.Y))
360+
self.text.set_position(pos + self._text_shift())
372361
self.text.draw(renderer)
373362
self.stale = False
374363

0 commit comments

Comments
 (0)