-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Merged streamline examples #8336
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
Changes from 1 commit
bf2b43b
92b1196
913fdb7
d56b5ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
files
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ a vector field. In addition to simply plotting the streamlines, it allows you | |
to map the colors and/or line widths of streamlines to a separate parameter, | ||
such as the speed or local intensity of the vector field. | ||
|
||
.. plot:: gallery/images_contours_and_fields/streamplot_features.py | ||
.. plot:: mpl_examples/images_contours_and_fields/streamplot_demo.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too, 'streamplot_demo.py' should be changed into 'plot_streamplot.py', shouldn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
This feature complements the :meth:`~matplotlib.pyplot.quiver` function for | ||
plotting vector fields. Thanks to Tom Flannaghan and Tony Yu for adding the | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,39 +2,42 @@ | |
========== | ||
Streamplot | ||
========== | ||
A streamplot, or streamline plot, is used to display 2D vector fields. This | ||
|
||
A stream plot, or stream line plot, is used to display 2D vector fields. This | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. streamline There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All done. |
||
example shows a few features of the stream plot function: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stream plot <- streamplot? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, when it comes to English, I may be totally wrong, but I think "the streamplot function" may be more correct than the current "the stream plot function", as it is refering to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think generally, "streamline" is a word and "streamplot" is not, unless you're referring to the function itself (as in this case.) |
||
|
||
* Varying the color along a streamline. | ||
* Varying the density of streamlines. | ||
* Varying the color along a stream line. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. streamline |
||
* Varying the density of stream lines. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. streamlines |
||
* Varying the line width along a stream line. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stream line <- streamline? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. streamline |
||
* Controlling the start points of streamlines. | ||
* Streamlines skipping masked regions and NaN values. | ||
* Controlling the starting points of stream lines. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. streamlines |
||
* Stream lines skipping masked regions and NaN values. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Streamlines |
||
""" | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import matplotlib.gridspec as gridspec | ||
|
||
w = 3 | ||
Y, X = np.mgrid[-w:w:100j, -w:w:100j] | ||
U = -1 - X**2 + Y | ||
V = 1 + X - Y**2 | ||
speed = np.sqrt(U*U + V*V) | ||
|
||
fig = plt.figure() | ||
fig = plt.figure(figsize=(7, 9)) | ||
gs = gridspec.GridSpec(nrows=3, ncols=2, height_ratios=[1, 1, 2]) | ||
|
||
# Varying density along a streamline | ||
ax0 = fig.add_subplot(321) | ||
ax0 = fig.add_subplot(gs[0, 0]) | ||
ax0.streamplot(X, Y, U, V, density=[0.5, 1]) | ||
ax0.set_title('Varying Density') | ||
|
||
# Varying color along a streamline | ||
ax1 = fig.add_subplot(322) | ||
strm = ax1.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=plt.cm.autumn) | ||
ax1 = fig.add_subplot(gs[0, 1]) | ||
strm = ax1.streamplot(X, Y, U, V, color=U, linewidth=2, cmap='autumn') | ||
fig.colorbar(strm.lines) | ||
ax1.set_title('Varying color') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Varying Color? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
# Varying line width along a streamline | ||
ax2 = fig.add_subplot(323) | ||
ax2 = fig.add_subplot(gs[1, 0]) | ||
lw = 5*speed / speed.max() | ||
ax2.streamplot(X, Y, U, V, density=0.6, color='k', linewidth=lw) | ||
ax2.set_title('Varying Line Width') | ||
|
@@ -45,16 +48,15 @@ | |
U, V = np.mgrid[-3:3:100j, 0:0:100j] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason for changing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have kept U, V exactly same as they are in previous streamplot_demo_start_points.py. But if I comment out above lines and use same U,V everywhere then I get this plot - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I think that I understand why the current situation was weird for both of us! The current example in the official docs is indeed the one that you are refering to. However, the starting point example was changed in #6672 (by myself, which is why I was having the feeling that you changed U and V here) to use the same data as the other streamplot examples, which I think is really more demonstrative to show the different plotting options of |
||
seed_points = np.array([[-2, -1, 0, 1, 2, -1], [-2, -1, 0, 1, 2, 2]]) | ||
|
||
ax3 = fig.add_subplot(324) | ||
ax3 = fig.add_subplot(gs[1, 1]) | ||
strm = ax3.streamplot(X, Y, U, V, color=U, linewidth=2, | ||
cmap=plt.cm.autumn, start_points=seed_points.T) | ||
cmap='autumn', start_points=seed_points.T) | ||
fig.colorbar(strm.lines) | ||
ax3.set_title('Controlling Starting Points') | ||
|
||
# Displaying the starting points with red symbols. | ||
# Displaying the starting points with blue symbols. | ||
ax3.plot(seed_points[0], seed_points[1], 'bo') | ||
|
||
ax3.axis((-3, 3, -3, 3)) | ||
ax3.axis((-w, w, -w, w)) | ||
|
||
# Create a mask | ||
w = 3 | ||
|
@@ -68,12 +70,13 @@ | |
U[:20, :20] = np.nan | ||
U = np.ma.array(U, mask=mask) | ||
|
||
ax4 = fig.add_subplot(325) | ||
ax4 = fig.add_subplot(gs[2:, :]) | ||
ax4.streamplot(X, Y, U, V, color='r') | ||
ax4.set_title('Streamline with Masking') | ||
ax4.set_title('Streamplot with Masking') | ||
|
||
ax4.imshow(~mask, extent=(-w, w, -w, w), alpha=0.5, | ||
interpolation='nearest', cmap=plt.cm.gray, aspect='auto') | ||
interpolation='nearest', cmap='gray', aspect='auto') | ||
ax4.set_aspect('equal') | ||
|
||
plt.tight_layout() | ||
plt.show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'streamplot_demo.py' should be changed into 'plot_streamplot.py', shouldn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.