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

Skip to content

Commit d190205

Browse files
committed
Add what's new/example for no broken streamlines
1 parent aaeb4ea commit d190205

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Add option to plt.streamplot to not break streamlines
2+
-----------------------------------------------------
3+
4+
It is now possible to specify that streamplots have continuous, unbroken
5+
streamlines. Previously streamlines would end to limit the number of lines
6+
within a single grid cell. See the difference between the plots below:
7+
8+
.. plot::
9+
10+
import matplotlib.pyplot as plt
11+
import numpy as np
12+
13+
w = 3
14+
Y, X = np.mgrid[-w:w:100j, -w:w:100j]
15+
U = -1 - X**2 + Y
16+
V = 1 + X - Y**2
17+
speed = np.sqrt(U**2 + V**2)
18+
19+
fig, (ax0, ax1) = plt.subplots(1, 2, sharex=True)
20+
21+
ax0.streamplot(X, Y, U, V, broken_streamlines=True)
22+
ax0.set_title('broken_streamlines=True')
23+
24+
ax1.streamplot(X, Y, U, V, broken_streamlines=False)
25+
ax1.set_title('broken_streamlines=False')

examples/images_contours_and_fields/plot_streamplot.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* Varying the line width along a streamline.
1212
* Controlling the starting points of streamlines.
1313
* Streamlines skipping masked regions and NaN values.
14+
* Unbroken streamlines even when exceeding the limit of lines within a single
15+
grid cell.
1416
"""
1517
import numpy as np
1618
import matplotlib.pyplot as plt
@@ -61,13 +63,17 @@
6163
U[:20, :20] = np.nan
6264
U = np.ma.array(U, mask=mask)
6365

64-
ax4 = fig.add_subplot(gs[2:, :])
66+
ax4 = fig.add_subplot(gs[2, 0])
6567
ax4.streamplot(X, Y, U, V, color='r')
6668
ax4.set_title('Streamplot with Masking')
6769

6870
ax4.imshow(~mask, extent=(-w, w, -w, w), alpha=0.5, cmap='gray', aspect='auto')
6971
ax4.set_aspect('equal')
7072

73+
ax5 = fig.add_subplot(gs[2, 1])
74+
ax5.streamplot(X, Y, U, V, broken_streamlines=False)
75+
ax5.set_title('Streamplot with with unbroken streamlines')
76+
7177
plt.tight_layout()
7278
plt.show()
7379
#############################################################################

lib/matplotlib/streamplot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
1919
cmap=None, norm=None, arrowsize=1, arrowstyle='-|>',
2020
minlength=0.1, transform=None, zorder=None, start_points=None,
21-
maxlength=4.0, integration_direction='both', broken_streamlines=True):
21+
maxlength=4.0, integration_direction='both',
22+
broken_streamlines=True):
2223
"""
2324
Draw streamlines of a vector flow.
2425

0 commit comments

Comments
 (0)