8000 Backport PR #19619: Fix bug in shape assignment · meeseeksmachine/matplotlib@d65d411 · GitHub
[go: up one dir, main page]

Skip to content

Commit d65d411

Browse files
jklymakmeeseeksmachine
authored andcommitted
Backport PR matplotlib#19619: Fix bug in shape assignment
1 parent da05621 commit d65d411

12 files changed

+8537
-7779
lines changed

lib/matplotlib/streamplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ def _integrate_rk12(x0, y0, dmap, f, maxlength):
572572
dx2 = ds * 0.5 * (k1x + k2x)
573573
dy2 = ds * 0.5 * (k1y + k2y)
574574

575-
nx, ny = dmap.grid.shape
575+
ny, nx = dmap.grid.shape
576576
# Error is normalized to the axes coordinates
577577
error = np.hypot((dx2 - dx1) / (nx - 1), (dy2 - dy1) / (ny - 1))
578578

Binary file not shown.
Loading

lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_colormap.svg

Lines changed: 2267 additions & 2179 deletions
Loading
Binary file not shown.
Loading

lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_linewidth.svg

Lines changed: 2819 additions & 2268 deletions
Loading
Binary file not shown.
Loading

lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_masks_and_nans.svg

Lines changed: 3437 additions & 3301 deletions
Loading
Binary file not shown.

lib/matplotlib/tests/test_streamplot.py

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
31
import numpy as np
42
from numpy.testing import assert_array_almost_equal
53
import pytest
@@ -8,19 +6,15 @@
86
import matplotlib.transforms as mtransforms
97

108

11-
on_win = (sys.platform == 'win32')
12-
on_mac = (sys.platform == 'darwin')
13-
14-
159
def velocity_field():
16-
Y, X = np.mgrid[-3:3:100j, -3:3:100j]
10+
Y, X = np.mgrid[-3:3:100j, -3:3:200j]
1711
U = -1 - X**2 + Y
1812
V = 1 + X - Y**2
1913
return X, Y, U, V
2014

2115

2216
def swirl_velocity_field():
23-
x = np.linspace(-3., 3., 100)
17+
x = np.linspace(-3., 3., 200)
2418
y = np.linspace(-3., 3., 100)
2519
X, Y = np.meshgrid(x, y)
2620
a = 0.1
@@ -29,7 +23,8 @@ def swirl_velocity_field():
2923
return x, y, U, V
3024

3125

32-
@image_comparison(['streamplot_startpoints'], remove_text=True, style='mpl20')
26+
@image_comparison(['streamplot_startpoints'], remove_text=True, style='mpl20',
27+
tol=0.513)
3328
def test_startpoints():
3429
X, Y, U, V = velocity_field()
3530
start_x = np.linspace(X.min(), X.max(), 10)
@@ -39,51 +34,39 @@ def test_startpoints():
3934
plt.plot(start_x, start_y, 'ok')
4035

4136

42-
@image_comparison(['streamplot_colormap'],
43-
tol=.04, remove_text=True, style='mpl20')
37+
@image_comparison(['streamplot_colormap'], remove_text=True, style='mpl20')
4438
def test_colormap():
45-
# Remove this line when this test image is regenerated.
46-
plt.rcParams['pcolormesh.snap'] = False
47-
4839
X, Y, U, V = velocity_field()
4940
plt.streamplot(X, Y, U, V, color=U, density=0.6, linewidth=2,
5041
cmap=plt.cm.autumn)
5142
plt.colorbar()
5243

5344

54-
@image_comparison(['streamplot_linewidth'], remove_text=True, style='mpl20')
45+
@image_comparison(['streamplot_linewidth'], remove_text=True, style='mpl20',
46+
tol=0.002)
5547
def test_linewidth():
5648
X, Y, U, V = velocity_field()
5749
speed = np.hypot(U, V)
5850
lw = 5 * speed / speed.max()
59-
# Compatibility for old test image
60-
df = 25 / 30
6151
ax = plt.figure().subplots()
62-
ax.set(xlim=(-3.0, 2.9999999999999947),
63-
ylim=(-3.0000000000000004, 2.9999999999999947))
64-
ax.streamplot(X, Y, U, V, density=[0.5 * df, 1. * df], color='k',
65-
linewidth=lw)
52+
ax.streamplot(X, Y, U, V, density=[0.5, 1], color='k', linewidth=lw)
6653

6754

6855
@image_comparison(['streamplot_masks_and_nans'],
69-
remove_text=True, style='mpl20', tol=0.04 if on_win else 0)
56+
remove_text=True, style='mpl20')
7057
def test_masks_and_nans():
7158
X, Y, U, V = velocity_field()
7259
mask = np.zeros(U.shape, dtype=bool)
73-
mask[40:60, 40:60] = 1
74-
U[:20, :20] = np.nan
60+
mask[40:60, 80:120] = 1
61+
U[:20, :40] = np.nan
7562
U = np.ma.array(U, mask=mask)
76-
# Compatibility for old test image
7763
ax = plt.figure().subplots()
78-
ax.set(xlim=(-3.0, 2.9999999999999947),
79-
ylim=(-3.0000000000000004, 2.9999999999999947))
8064
with np.errstate(invalid='ignore'):
8165
ax.streamplot(X, Y, U, V, color=U, cmap=plt.cm.Blues)
8266

8367

8468
@image_comparison(['streamplot_maxlength.png'],
85-
remove_text=True, style='mpl20',
86-
tol=0.002 if on_mac else 0)
69+
remove_text=True, style='mpl20', tol=0.302)
8770
def test_maxlength():
8871
x, y, U, V = swirl_velocity_field()
8972
ax = plt.figure().subplots()
@@ -95,7 +78,7 @@ def test_maxlength():
9578

9679

9780
@image_comparison(['streamplot_direction.png'],
98-
remove_text=True, style='mpl20')
81+
remove_text=True, style='mpl20', tol=0.056)
9982
def test_direction():
10083
x, y, U, V = swirl_velocity_field()
10184
plt.streamplot(x, y, U, V, integration_direction='backward',

0 commit comments

Comments
 (0)
0