From 16c67c8c4cbb6174853738fa7fe401109861e0c2 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 24 May 2022 08:57:30 +0200 Subject: [PATCH] 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. --- lib/matplotlib/quiver.py | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index 14339f54b938..2ebf28f0fe59 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -19,7 +19,7 @@ import numpy as np from numpy import ma -from matplotlib import _api, cbook, _docstring, font_manager +from matplotlib import _api, cbook, _docstring import matplotlib.artist as martist import matplotlib.collections as mcollections from matplotlib.patches import CirclePolygon @@ -303,13 +303,11 @@ def __init__(self, Q, X, Y, U, label, self.labelcolor = labelcolor self.fontproperties = fontproperties or dict() self.kw = kwargs - _fp = self.fontproperties self.text = mtext.Text( text=label, horizontalalignment=self.halign[self.labelpos], verticalalignment=self.valign[self.labelpos], - fontproperties=font_manager.FontProperties._from_any(_fp)) - + fontproperties=self.fontproperties) if self.labelcolor is not None: self.text.set_color(self.labelcolor) self._dpi_at_last_init = None @@ -346,29 +344,20 @@ def _init(self): self.vector.set_figure(self.get_figure()) self._dpi_at_last_init = self.Q.axes.figure.dpi - def _text_x(self, x): - if self.labelpos == 'E': - return x + self.labelsep - elif self.labelpos == 'W': - return x - self.labelsep - else: - return x - - def _text_y(self, y): - if self.labelpos == 'N': - return y + self.labelsep - elif self.labelpos == 'S': - return y - self.labelsep - else: - return y + def _text_shift(self): + return { + "N": (0, +self.labelsep), + "S": (0, -self.labelsep), + "E": (+self.labelsep, 0), + "W": (-self.labelsep, 0), + }[self.labelpos] @martist.allow_rasterization def draw(self, renderer): self._init() self.vector.draw(renderer) - x, y = self.get_transform().transform((self.X, self.Y)) - self.text.set_x(self._text_x(x)) - self.text.set_y(self._text_y(y)) + pos = self.get_transform().transform((self.X, self.Y)) + self.text.set_position(pos + self._text_shift()) self.text.draw(renderer) self.stale = False pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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