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

Skip to content

Commit 92b1196

Browse files
patniharshitdstansby
authored andcommitted
Add gridspec to have equal aspect ratio and remove references of deleted
files
1 parent bf2b43b commit 92b1196

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

doc/users/prev_whats_new/whats_new_1.2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ In addition to simply plotting the streamlines of the vector field,
153153
line widths of the streamlines to a separate parameter, such as the speed or
154154
local intensity of the vector field.
155155

156-
.. plot:: gallery/images_contours_and_fields/streamplot_features.py
156+
.. plot:: mpl_examples/images_contours_and_fields/streamplot_demo.py
157157

158158

159159
New hist functionality

doc/users/screenshots.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ a vector field. In addition to simply plotting the streamlines, it allows you
7171
to map the colors and/or line widths of streamlines to a separate parameter,
7272
such as the speed or local intensity of the vector field.
7373

74-
.. plot:: gallery/images_contours_and_fields/streamplot_features.py
74+
.. plot:: mpl_examples/images_contours_and_fields/streamplot_demo.py
7575

7676
This feature complements the :meth:`~matplotlib.pyplot.quiver` function for
7777
plotting vector fields. Thanks to Tom Flannaghan and Tony Yu for adding the

examples/images_contours_and_fields/streamplot_demo.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,42 @@
22
==========
33
Streamplot
44
==========
5-
A streamplot, or streamline plot, is used to display 2D vector fields. This
5+
6+
A stream plot, or stream line plot, is used to display 2D vector fields. This
67
example shows a few features of the stream plot function:
78
8-
* Varying the color along a streamline.
9-
* Varying the density of streamlines.
9+
* Varying the color along a stream line.
10+
* Varying the density of stream lines.
1011
* Varying the line width along a stream line.
11-
* Controlling the start points of streamlines.
12-
* Streamlines skipping masked regions and NaN values.
12+
* Controlling the starting points of stream lines.
13+
* Stream lines skipping masked regions and NaN values.
1314
"""
1415
import numpy as np
1516
import matplotlib.pyplot as plt
17+
import matplotlib.gridspec as gridspec
1618

1719
w = 3
1820
Y, X = np.mgrid[-w:w:100j, -w:w:100j]
1921
U = -1 - X**2 + Y
2022
V = 1 + X - Y**2
2123
speed = np.sqrt(U*U + V*V)
2224

23-
fig = plt.figure()
25+
fig = plt.figure(figsize=(7, 9))
26+
gs = gridspec.GridSpec(nrows=3, ncols=2, height_ratios=[1, 1, 2])
2427

2528
# Varying density along a streamline
26-
ax0 = fig.add_subplot(321)
29+
ax0 = fig.add_subplot(gs[0, 0])
2730
ax0.streamplot(X, Y, U, V, density=[0.5, 1])
2831
ax0.set_title('Varying Density')
2932

3033
# Varying color along a streamline
31-
ax1 = fig.add_subplot(322)
32-
strm = ax1.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=plt.cm.autumn)
34+
ax1 = fig.add_subplot(gs[0, 1])
35+
strm = ax1.streamplot(X, Y, U, V, color=U, linewidth=2, cmap='autumn')
3336
fig.colorbar(strm.lines)
3437
ax1.set_title('Varying color')
3538

3639
# Varying line width along a streamline
37-
ax2 = fig.add_subplot(323)
40+
ax2 = fig.add_subplot(gs[1, 0])
3841
lw = 5*speed / speed.max()
3942
ax2.streamplot(X, Y, U, V, density=0.6, color='k', linewidth=lw)
4043
ax2.set_title('Varying Line Width')
@@ -45,16 +48,15 @@
4548
U, V = np.mgrid[-3:3:100j, 0:0:100j]
4649
seed_points = np.array([[-2, -1, 0, 1, 2, -1], [-2, -1, 0, 1, 2, 2]])
4750

48-
ax3 = fig.add_subplot(324)
51+
ax3 = fig.add_subplot(gs[1, 1])
4952
strm = ax3.streamplot(X, Y, U, V, color=U, linewidth=2,
50-
cmap=plt.cm.autumn, start_points=seed_points.T)
53+
cmap='autumn', start_points=seed_points.T)
5154
fig.colorbar(strm.lines)
5255
ax3.set_title('Controlling Starting Points')
5356

54-
# Displaying the starting points with red symbols.
57+
# Displaying the starting points with blue symbols.
5558
ax3.plot(seed_points[0], seed_points[1], 'bo')
56-
57-
ax3.axis((-3, 3, -3, 3))
59+
ax3.axis((-w, w, -w, w))
5860

5961
# Create a mask
6062
w = 3
@@ -68,12 +70,13 @@
6870
U[:20, :20] = np.nan
6971
U = np.ma.array(U, mask=mask)
7072

71-
ax4 = fig.add_subplot(325)
73+
ax4 = fig.add_subplot(gs[2:, :])
7274
ax4.streamplot(X, Y, U, V, color='r')
73-
ax4.set_title('Streamline with Masking')
75+
ax4.set_title('Streamplot with Masking')
7476

7577
ax4.imshow(~mask, extent=(-w, w, -w, w), alpha=0.5,
76-
interpolation='nearest', cmap=plt.cm.gray, aspect='auto')
78+
interpolation='nearest', cmap='gray', aspect='auto')
79+
ax4.set_aspect('equal')
7780

7881
plt.tight_layout()
7982
plt.show()

0 commit comments

Comments
 (0)