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

Skip to content

Commit 4eaf3a6

Browse files
authored
Merge pull request #7417 from efiring/merge_from_v2.x
Merge from v2.x
2 parents 6709b59 + 939a670 commit 4eaf3a6

29 files changed

+44
-4
lines changed

lib/matplotlib/quiver.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ def _parse_args(*args):
392392
return X, Y, U, V, C
393393

394394

395+
def _check_consistent_shapes(*arrays):
396+
all_shapes = set(a.shape for a in arrays)
397+
if len(all_shapes) != 1:
398+
raise ValueError('The shapes of the passed in arrays do not match.')
399+
400+
395401
class Quiver(mcollections.PolyCollection):
396402
"""
397403
Specialized PolyCollection for arrows.
@@ -1124,9 +1130,11 @@ def set_UVC(self, U, V, C=None):
11241130
x, y, u, v, c = delete_masked_points(self.x.ravel(),
11251131
self.y.ravel(),
11261132
self.u, self.v, c)
1133+
_check_consistent_shapes(x, y, u, v, c)
11271134
else:
11281135
x, y, u, v = delete_masked_points(self.x.ravel(), self.y.ravel(),
11291136
self.u, self.v)
1137+
_check_consistent_shapes(x, y, u, v)
11301138

11311139
magnitude = np.hypot(u, v)
11321140
flags, barbs, halves, empty = self._find_tails(magnitude,
@@ -1151,16 +1159,17 @@ def set_UVC(self, U, V, C=None):
11511159

11521160
def set_offsets(self, xy):
11531161
"""
1154-
Set the offsets for the barb polygons. This saves the offets passed in
1155-
and actually sets version masked as appropriate for the existing U/V
1156-
data. *offsets* should be a sequence.
1162+
Set the offsets for the barb polygons. This saves the offsets passed
1163+
in and actually sets version masked as appropriate for the existing
1164+
U/V data. *offsets* should be a sequence.
11571165
11581166
ACCEPTS: sequence of pairs of floats
11591167
"""
11601168
self.x = xy[:, 0]
11611169
self.y = xy[:, 1]
11621170
x, y, u, v = delete_masked_points(self.x.ravel(), self.y.ravel(),
11631171
self.u, self.v)
1172+
_check_consistent_shapes(x, y, u, v)
11641173
xy = np.hstack((x[:, np.newaxis], y[:, np.newaxis]))
11651174
mcollections.PolyCollection.set_offsets(self, xy)
11661175
self.stale = True
Loading
Loading

lib/matplotlib/tests/test_axes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4713,3 +4713,18 @@ def test_fillbetween_cycle():
47134713
face_target = mcolors.to_rgba('C{}'.format(j))
47144714
assert tuple(cc.get_facecolors().squeeze()) == tuple(face_target)
47154715
assert tuple(cc.get_edgecolors().squeeze()) == tuple(edge_target)
4716+
4717+
4718+
@cleanup
4719+
def test_log_margins():
4720+
plt.rcParams['axes.autolimit_mode'] = 'data'
4721+
fig, ax = plt.subplots()
4722+
margin = 0.05
4723+
ax.set_xmargin(margin)
4724+
ax.semilogx([1, 10], [1, 10])
4725+
xlim0, xlim1 = ax.get_xlim()
4726+
transform = ax.xaxis.get_transform()
4727+
xlim0t, xlim1t = transform.transform([xlim0, xlim1])
4728+
x0t, x1t = transform.transform([1, 10])
4729+
delta = (x1t - x0t) * margin
4730+
assert_allclose([xlim0t + delta, xlim1t - delta], [x0t, x1t])

lib/matplotlib/tests/test_quiver.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import print_function
22
import warnings
33
import numpy as np
4+
from nose.tools import raises
45
import sys
56
from matplotlib import pyplot as plt
67
from matplotlib.testing.decorators import cleanup
@@ -132,6 +133,21 @@ def test_barbs():
132133
sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3),
133134
cmap='viridis')
134135

136+
137+
@cleanup
138+
@raises(ValueError)
139+
def test_bad_masked_sizes():
140+
'Test error handling when given differing sized masked arrays'
141+
x = np.arange(3)
142+
y = np.arange(3)
143+
u = np.ma.array(15. * np.ones((4,)))
144+
v = np.ma.array(15. * np.ones_like(u))
145+
u[1] = np.ma.masked
146+
v[1] = np.ma.masked
147+
fig, ax = plt.subplots()
148+
ax.barbs(x, y, u, v)
149+
150+
135151
if __name__ == '__main__':
136152
import nose
137153
nose.runmodule()

lib/matplotlib/ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ def view_limits(self, vmin, vmax):
20232023
"Data has no positive values, and therefore can not be "
20242024
"log-scaled.")
20252025

2026-
if vmin <= minpos:
2026+
if vmin <= 0:
20272027
vmin = minpos
20282028

20292029
if rcParams['axes.autolimit_mode'] == 'round_numbers':

0 commit comments

Comments
 (0)