8000 Merge pull request #8971 from dopplershift/barb-units · matplotlib/matplotlib@aff47a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit aff47a6

Browse files
authored
Merge pull request #8971 from dopplershift/barb-units
ENH: Support x,y units for barbs/quiver
2 parents f077d49 + b1dc677 commit aff47a6

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4573,11 +4573,25 @@ def quiverkey(self, *args, **kw):
45734573
return qk
45744574
quiverkey.__doc__ = mquiver.QuiverKey.quiverkey_doc
45754575

4576+
# Handle units for x and y, if they've been passed
4577+
def _quiver_units(self, args, kw):
4578+
if len(args) > 3:
4579+
x, y = args[0:2]
4580+
self._process_unit_info(xdata=x, ydata=y, kwargs=kw)
4581+
x = self.convert_xunits(x)
4582+
y = self.convert_yunits(y)
4583+
return (x, y) + args[2:]
4584+
return args
4585+
45764586
# args can by a combination if X, Y, U, V, C and all should be replaced
45774587
@_preprocess_data(replace_all_args=True, label_namer=None)
45784588
def quiver(self, *args, **kw):
45794589
if not self._hold:
45804590
self.cla()
4591+
4592+
# Make sure units are handled for x and y values
4593+
args = self._quiver_units(args, kw)
4594+
45814595
q = mquiver.Quiver(self, *args, **kw)
45824596

45834597
self.add_collection(q, autolim=True)
@@ -4627,6 +4641,10 @@ def barbs(self, *args, **kw):
46274641
"""
46284642
if not self._hold:
46294643
self.cla()
4644+
4645+
# Make sure units are handled for x and y values
4646+
args = self._quiver_units(args, kw)
4647+
46304648
b = mquiver.Barbs(self, *args, **kw)
46314649
self.add_collection(b, autolim=True)
46324650
self.autoscale_view()

lib/matplotlib/tests/test_axes.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5040,6 +5040,22 @@ def test_large_offset():
50405040
fig.canvas.draw()
50415041

50425042

5043+
def test_barb_units():
5044+
fig, ax = plt.subplots()
5045+
dates = [datetime.datetime(2017, 7, 15, 18, i) for i in range(0, 60, 10)]
5046+
y = np.linspace(0, 5, len(dates))
5047+
u = v = np.linspace(0, 50, len(dates))
5048+
ax.barbs(dates, y, u, v)
5049+
5050+
5051+
def test_quiver_units():
5052+
fig, ax = plt.subplots()
5053+
dates = [datetime.datetime(2017, 7, 15, 18, i) for i in range(0, 60, 10)]
5054+
y = np.linspace(0, 5, len(dates))
5055+
u = v = np.linspace(0, 50, len(dates))
5056+
ax.quiver(dates, y, u, v)
5057+
5058+
50435059
def test_bar_color_cycle():
50445060
ccov = mcolors.colorConverter.to_rgb
50455061
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)
0