8000 Fix bug in shape assignment by r03ert0 · Pull Request #19619 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix bug in shape assignment #19619

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 2 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/matplotlib/streamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def _integrate_rk12(x0, y0, dmap, f, maxlength):
dx2 = ds * 0.5 * (k1x + k2x)
dy2 = ds * 0.5 * (k1y + k2y)

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

Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4,446 changes: 2,267 additions & 2,179 deletions lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_colormap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5,087 changes: 2,819 additions & 2,268 deletions lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_linewidth.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6,738 changes: 3,437 additions & 3,301 deletions lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_masks_and_nans.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
43 changes: 13 additions & 30 deletions lib/matplotlib/tests/test_streamplot.py
6D47
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sys

import numpy as np
from numpy.testing import assert_array_almost_equal
import pytest
Expand All @@ -8,19 +6,15 @@
import matplotlib.transforms as mtransforms


on_win = (sys.platform == 'win32')
on_mac = (sys.platform == 'darwin')


def velocity_field():
Y, X = np.mgrid[-3:3:100j, -3:3:100j]
Y, X = np.mgrid[-3:3:100j, -3:3:200j]
U = -1 - X**2 + Y
V = 1 + X - Y**2
return X, Y, U, V


def swirl_velocity_field():
x = np.linspace(-3., 3., 100)
x = np.linspace(-3., 3., 200)
y = np.linspace(-3., 3., 100)
X, Y = np.meshgrid(x, y)
a = 0.1
Expand All @@ -29,7 +23,8 @@ def swirl_velocity_field():
return x, y, U, V


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


@image_comparison(['streamplot_colormap'],
tol=.04, remove_text=True, style='mpl20')
@image_comparison(['streamplot_colormap'], remove_text=True, style='mpl20')
def test_colormap():
# Remove this line when this test image is regenerated.
plt.rcParams['pcolormesh.snap'] = False

X, Y, U, V = velocity_field()
plt.streamplot(X, Y, U, V, color=U, density=0.6, linewidth=2,
cmap=plt.cm.autumn)
plt.colorbar()


@image_comparison(['streamplot_linewidth'], remove_text=True, style='mpl20')
@image_comparison(['streamplot_linewidth'], remove_text=True, style='mpl20',
tol=0.002)
def test_linewidth():
X, Y, U, V = velocity_field()
speed = np.hypot(U, V)
lw = 5 * speed / speed.max()
# Compatibility for old test image
df = 25 / 30
ax = plt.figure().subplots()
ax.set(xlim=(-3.0, 2.9999999999999947),
ylim=(-3.0000000000000004, 2.9999999999999947))
ax.streamplot(X, Y, U, V, density=[0.5 * df, 1. * df], color='k',
linewidth=lw)
ax.streamplot(X, Y, U, V, density=[0.5, 1], color='k', linewidth=lw)


@image_comparison(['streamplot_masks_and_nans'],
remove_text=True, style='mpl20', tol=0.04 if on_win else 0)
remove_text=True, style='mpl20')
def test_masks_and_nans():
X, Y, U, V = velocity_field()
mask = np.zeros(U.shape, dtype=bool)
mask[40:60, 40:60] = 1
U[:20, :20] = np.nan
mask[40:60, 80:120] = 1
U[:20, :40] = np.nan
U = np.ma.array(U, mask=mask)
# Compatibility for old test image
ax = plt.figure().subplots()
ax.set(xlim=(-3.0, 2.9999999999999947),
ylim=(-3.0000000000000004, 2.9999999999999947))
with np.errstate(invalid='ignore'):
ax.streamplot(X, Y, U, V, color=U, cmap=plt.cm.Blues)


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


@image_comparison(['streamplot_direction.png'],
remove_text=True, style='mpl20')
remove_text=True, style='mpl20', tol=0.056)
def test_direction():
x, y, U, V = swirl_velocity_field()
plt.streamplot(x, y, U, V, integration_direction='backward',
Expand Down
0