Skip to content
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

Consistent grid sizes in streamplot. #2700

Merged
merged 1 commit into from Jan 1, 2014
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG
@@ -1,3 +1,7 @@
2013-12-30 Made streamplot grid size consistent for different types of density
argument. A 30x30 grid is now used for both density=1 and
density=(1, 1).

2013-11-28 Added qhull extension module to perform Delaunay triangulation more
robustly than before. It is used by tri.Triangulation (and hence
all pyplot.tri* methods) and mlab.griddata. Deprecated
Expand Down
7 changes: 7 additions & 0 deletions doc/users/whats_new.rst
Expand Up @@ -74,6 +74,13 @@ Added `FormatStrFormatterNewStyle` which does the same job as
`FormatStrFormatter`, but accepts new-style formatting strings
instead of printf-style formatting strings

Consistent grid sizes in streamplots
````````````````````````````````````
:func:`~matplotlib.pyplot.streamplot` uses a base grid size of 30x30 for both
`density=1` and `density=(1, 1)`. Previously a grid size of 30x30 was used for
`density=1`, but a grid size of 25x25 was used for `density=(1, 1)`.


Date handling
-------------

Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/streamplot.py
Expand Up @@ -31,7 +31,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
the number of columns should match x.
*density* : float or 2-tuple
Controls the closeness of streamlines. When `density = 1`, the domain
is divided into a 25x25 grid---*density* linearly scales this grid.
is divided into a 30x30 grid---*density* linearly scales this grid.
Each cell in the grid can have, at most, one traversing streamline.
For different densities in each direction, use [density_x, density_y].
*linewidth* : numeric or 2d array
Expand Down Expand Up @@ -313,8 +313,8 @@ def __init__(self, density):
self.nx = self.ny = int(30 * density)
else:
assert len(density) == 2
self.nx = int(25 * density[0])
self.ny = int(25 * density[1])
self.nx = int(30 * density[0])
self.ny = int(30 * density[1])
self._mask = np.zeros((self.ny, self.nx))
self.shape = self._mask.shape

Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/tests/test_streamplot.py
Expand Up @@ -28,7 +28,9 @@ def test_linewidth():
X, Y, U, V = velocity_field()
speed = np.sqrt(U*U + V*V)
lw = 5*speed/speed.max()
plt.streamplot(X, Y, U, V, density=[0.5, 1], color='k', linewidth=lw)
df = 25. / 30. # Compatibility factor for old test image
plt.streamplot(X, Y, U, V, density=[0.5 * df, 1. * df], color='k',
linewidth=lw)


@image_comparison(baseline_images=['streamplot_masks_and_nans_test_image'])
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/tests/test_transforms.py
Expand Up @@ -102,8 +102,9 @@ def test_pre_transform_plotting():
u = 2*np.sin(x) + np.cos(y[:, np.newaxis])
v = np.sin(x) - np.cos(y[:, np.newaxis])

df = 25. / 30. # Compatibility factor for old test image
ax.streamplot(x, y, u, v, transform=times10 + ax.transData,
density=(1, 1), linewidth=u**2 + v**2)
density=(df, df), linewidth=u**2 + v**2)

# reduce the vector data down a bit for barb and quiver plotting
x, y = x[::3], y[::3]
Expand Down