Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Small cleanups to QuiverKey. #23119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions lib/matplotlib/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down