8000 Merge remote-tracking branch 'upstream/v1.3.x' · matplotlib/matplotlib@d316904 · GitHub
[go: up one dir, main page]

Skip to content

Commit d316904

Browse files
committed
Merge remote-tracking branch 'upstream/v1.3.x'
- quiver had two functions added next to each other, easy merge - all_figures.html had non-trivial due to prior refactor on master - changes to axes.py needed to be split between _axes.py and _base.py Conflicts: lib/matplotlib/axes/_axes.py lib/matplotlib/backends/web_backend/all_figures.html lib/matplotlib/quiver.py
2 parents ee41a0c + a7d9266 commit d316904

File tree

13 files changed

+100
-40
lines changed

13 files changed

+100
-40
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ script:
3636
after_failure:
3737
- tar cjf result_images.tar.bz2 result_images
3838
- travis-artifacts upload --path result_images.tar.bz2
39-
- echo https://s3.amazonaws.com/matplotlib-test-results/artifacts/${TRAVIS_BUILD_NUMBER}/${TRAVIS_JOB_NUMBER}/result_images.tar.bz2
39+
- echo "The result images will only be uploaded if they are on the matplotlib/matplotlib repo - this is for security reasons to prevent arbitrary PRs echoing security details."
40+
- echo https://s3.amazonaws.com/matplotlib-test-results/artifacts/${TRAVIS_BUILD_NUMBER}/${TRAVIS_JOB_NUMBER}/result_images.tar.bz2

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4049,8 +4049,8 @@ def quiver(self, *args, **kw):
40494049
if not self._hold:
40504050
self.cla()
40514051
q = mquiver.Quiver(self, *args, **kw)
4052-
self.add_collection(q, False)
4053-
self.update_datalim(q.XY)
4052+
4053+
self.add_collection(q, True)
40544054
self.autoscale_view()
40554055
return q
40564056
quiver.__doc__ = mquiver.Quiver.quiver_doc
@@ -4091,7 +4091,6 @@ def barbs(self, *args, **kw):
40914091
self.cla()
40924092
b = mquiver.Barbs(self, *args, **kw)
40934093
self.add_collection(b)
4094-
self.update_datalim(b.get_offsets())
40954094
self.autoscale_view()
40964095
return b
40974096

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,10 +1451,7 @@ def add_collection(self, collection, autolim=True):
14511451
if collection.get_clip_path() is None:
14521452
collection.set_clip_path(self.patch)
14531453

1454-
if (autolim and
1455-
collection._paths is not None and
1456-
len(collection._paths) and
1457-
len(collection._offsets)):
1454+
if autolim:
14581455
self.update_datalim(collection.get_datalim(self.transData))
14591456

14601457
collection._remove_method = lambda h: self.collections.remove(h)

lib/matplotlib/backends/web_backend/all_figures.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
var websocket = new websocket_type(
2121
"{{ ws_uri }}" + "{{ fig_id }}" + "/ws");
2222
var fig = new mpl.figure(
23-
{{ repr(str(fig_id)) }}, websocket, mpl_ondownload, figure_div);
23+
"{{ fig_id }}", websocket, mpl_ondownload, figure_div);
2424

2525
fig.focus_on_mouseover = true;
2626

@@ -31,11 +31,13 @@
3131
{% end %}
3232
</script>
3333

34-
<title>MPL | WebAgg current figures</title>
34+
<title>MPL | WebAgg current figures</title>
3535

3636
</head>
3737
<body>
3838
<div id="mpl-warnings" class="mpl-warnings"></div>
39+
3940
<div id="figures" style="margin: 10px 10px;"></div>
41+
4042
</body>
4143
</html>

lib/matplotlib/collections.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ def get_datalim(self, transData):
192192
# get_path_collection_extents handles nan but not masked arrays
193193
offsets.shape = (-1, 2) # Make it Nx2
194194

195-
if paths:
195+
if len(paths) and len(offsets):
196196
result = mpath.get_path_collection_extents(
197197
transform.frozen(), paths, self.get_transforms(),
198198
offsets, transOffset.frozen())
199199
result = result.inverse_transformed(transData)
200200
else:
201-
result = transforms.Bbox([[0, 0], [0, 0]])
201+
result = transforms.Bbox.null()
202202
return result
203203

204204
def get_window_extent(self, renderer):
@@ -1716,9 +1716,6 @@ def convert_mesh_to_triangles(self, meshWidth, meshHeight, coordinates):
17161716

17171717
return triangles, colors
17181718

1719-
def get_datalim(self, transData):
1720-
return self._bbox
1721-
17221719
@allow_rasterization
17231720
def draw(self, renderer):
17241721
if not self.get_visible():

lib/matplotlib/compat/subprocess.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,25 @@
1818

1919
import subprocess
2020

21-
__all__ = ['Popen', 'PIPE', 'STDOUT', 'check_output']
21+
__all__ = ['Popen', 'PIPE', 'STDOUT', 'check_output', 'CalledProcessError']
2222

2323

2424
if hasattr(subprocess, 'Popen'):
2525
Popen = subprocess.Popen
2626
# Assume that it also has the other constants.
2727
PIPE = subprocess.PIPE
2828
STDOUT = subprocess.STDOUT
29+
CalledProcessError = subprocess.CalledProcessError
2930
else:
3031
# In restricted environments (such as Google App Engine), these are
3132
# non-existent. Replace them with dummy versions that always raise OSError.
3233
def Popen(*args, **kwargs):
3334
raise OSError("subprocess.Popen is not supported")
3435
PIPE = -1
3536
STDOUT = -2
37+
# There is no need to catch CalledProcessError. These stubs cannot raise
38+
# it. None in an except clause will simply not match any exceptions.
39+
CalledProcessError = None
3640

3741

3842
def _check_output(*popenargs, **kwargs):
@@ -75,5 +79,3 @@ def _check_output(*popenargs, **kwargs):
7579
check_output = subprocess.check_output
7680
else:
7781
check_output = _check_output
78-
79-
CalledProcessError = subprocess.CalledProcessError

lib/matplotlib/quiver.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,15 @@ def _init(self):
493493

494494
self._initialized = True
495495

496+
def get_datalim(self, transData):
497+
trans = self.get_transform()
498+
transOffset = self.get_offset_transform()
499+
full_transform = (trans - transData) + (transOffset - transData)
500+
XY = full_transform.transform(self.XY)
501+
bbox = transforms.Bbox.null()
502+
bbox.update_from_data_xy(XY, ignore=True)
503+
return bbox
504+
496505
@allow_rasterization
497506
def draw(self, renderer):
498507
self._init()

lib/matplotlib/streamplot.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
178178
lc.set_cmap(cmap)
179179
lc.set_norm(norm)
180180
axes.add_collection(lc)
181-
182-
axes.update_datalim(((x.min(), y.min()), (x.max(), y.max())))
183-
axes.autoscale_view(tight=True)
181+
axes.autoscale_view()
184182

185183
ac = matplotlib.collections.PatchCollection(arrows)
186184
stream_container = StreamplotSet(lc, ac)
Loading

lib/matplotlib/tests/test_axes.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,6 @@ def test_formatter_ticker():
6464
ax.set_xlabel( "x-label 005" )
6565
ax.autoscale_view()
6666

67-
@cleanup
68-
def test_add_collection():
69-
# Test if data limits are unchanged by adding an empty collection.
70-
# Github issue #1490, pull #1497.
71-
fig = matplotlib.figure.Figure()
72-
fig2 = matplotlib.figure.Figure()
73-
ax = fig.add_subplot(111)
74-
ax2 = fig2.add_subplot(111)
75-
coll = ax2.scatter([0, 1], [0, 1])
76-
ax.add_collection(coll)
77-
bounds = ax.dataLim.bounds
78-
coll = ax2.scatter([], [])
79-
ax.add_collection(coll)
80-
assert ax. 1241 dataLim.bounds == bounds
8167

8268
@image_comparison(baseline_images=["formatter_large_small"])
8369
def test_formatter_large_small():
@@ -87,6 +73,7 @@ def test_formatter_large_small():
8773
y = [1e64, 1.1e64]
8874
ax.plot(x, y)
8975

76+
9077
@image_comparison(baseline_images=["twin_axis_locaters_formatters"])
9178
def test_twin_axis_locaters_formatters():
9279
vals = np.linspace(0, 1, num=5, endpoint=True)

lib/matplotlib/tests/test_collections.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from nose.tools import assert_equal
1010
import numpy as np
11-
from numpy.testing import assert_array_equal
11+
from numpy.testing import assert_array_equal, assert_array_almost_equal
1212

1313
import matplotlib.pyplot as plt
1414
import matplotlib.collections as mcollections
@@ -400,9 +400,56 @@ def test_null_collection_datalim():
400400
col = mcollections.PathCollection([])
401401
col_data_lim = col.get_datalim(mtransforms.IdentityTransform())
402402
assert_array_equal(col_data_lim.get_points(),
403-
mtransforms.Bbox([[0, 0], [0, 0]]).get_points())
403+
mtransforms.Bbox.null().get_points())
404404

405405

406+
@cleanup
407+
def test_add_collection():
408+
# Test if data limits are unchanged by adding an empty collection.
409+
# Github issue #1490, pull #1497.
410+
ax = plt.axes()
411+
plt.figure()
412+
ax2 = plt.axes()
413+
coll = ax2.scatter([0, 1], [0, 1])
414+
ax.add_collection(coll)
415+
bounds = ax.dataLim.bounds
416+
coll = ax2.scatter([], [])
417+
ax.add_collection(coll)
418+
assert_equal(ax.dataLim.bounds, bounds)
419+
420+
421+
@cleanup
422+
def test_quiver_limits():
423+
ax = plt.axes()
424+
x, y = np.arange(8), np.arange(10)
425+
data = u = v = np.linspace(0, 10, 80).reshape(10, 8)
426+
q = plt.quiver(x, y, u, v)
427+
assert_equal(q.get_datalim(ax.transData).bounds, (0., 0., 7., 9.))
428+
429+
plt.figure()
430+
ax = plt.axes()
431+
x = np.linspace(-5, 10, 20)
432+
y = np.linspace(-2, 4, 10)
433+
y, x = np.meshgrid(y, x)
434+
trans = mtransforms.Affine2D().translate(25, 32) + ax.transData
435+
plt.quiver(x, y, np.sin(x), np.cos(y), transform=trans)
436+
assert_equal(ax.dataLim.bounds, (20.0, 30.0, 15.0, 6.0))
437+
438+
439+
@cleanup
440+
def test_barb_limits():
441+
ax = plt.axes()
442+
x = np.linspace(-5, 10, 20)
443+
y = np.linspace(-2, 4, 10)
444+
y, x = np.meshgrid(y, x)
445+
trans = mtransforms.Affine2D().translate(25, 32) + ax.transData
446+
plt.barbs(x, y, np.sin(x), np.cos(y), transform=trans)
447+
# The calculated bounds are approximately the bounds of the original data,
448+
# this is because the entire path is taken into account when updating the
449+
# datalim.
450+
assert_array_almost_equal(ax.dataLim.bounds, (20, 30, 15, 6),
451+
decimal=2)
452+
406453
if __name__ == '__main__':
407454
import nose
408455
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_pickle.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,14 @@ def test_complete():
153153
plt.subplot(3, 3, 5)
154154
plt.pcolor(data)
155155

156-
plt.subplot(3, 3, 6)
156+
ax = plt.subplot(3, 3, 6)
157+
ax.set_xlim(0, 7)
158+
ax.set_ylim(0, 9)
157159
plt.streamplot(x, y, u, v)
158160

159-
plt.subplot(3, 3, 7)
161+
ax = plt.subplot(3, 3, 7)
162+
ax.set_xlim(0, 7)
163+
ax.set_ylim(0, 9)
160164
plt.quiver(x, y, u, v)
161165

162166
plt.subplot(3, 3, 8)

lib/matplotlib/tests/test_streamplot.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import six
55

66
import numpy as np
7+
from numpy.testing import assert_array_almost_equal
78
import matplotlib.pyplot as plt
8-
from matplotlib.testing.decorators import image_comparison
9+
from matplotlib.testing.decorators import image_comparison, cleanup
10+
import matplotlib.transforms as mtransforms
911

1012

1113
def velocity_field():
@@ -43,6 +45,21 @@ def test_masks_and_nans():
4345
plt.streamplot(X, Y, U, V, color=U, cmap=plt.cm.Blues)
4446

4547

48+
@cleanup
49+
def test_streamplot_limits():
50+
ax = plt.axes()
51+
x = np.linspace(-5, 10, 20)
52+
y = np.linspace(-2, 4, 10)
53+
y, x = np.meshgrid(y, x)
54+
trans = mtransforms.Affine2D().translate(25, 32) + ax.transData
55+
plt.barbs(x, y, np.sin(x), np.cos(y), transform=trans)
56+
# The calculated bounds are approximately the bounds of the original data,
57+
# this is because the entire path is taken into account when updating the
58+
# datalim.
59+
assert_array_almost_equal(ax.dataLim.bounds, (20, 30, 15, 6),
60+
decimal=2)
61+
62+
4663
if __name__=='__main__':
4764
import nose
4865
nose.runmodule()

0 commit comments

Comments
 (0)
0