-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Merged and improved the streamplot demonstration #8082
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 all commits
08b2382
4618736
fadc12c
2d8f334
fc0ce67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
""" | ||
========== | ||
Streamplot | ||
========== | ||
|
||
Demo of the `streamplot` function. | ||
|
||
A streamplot, or streamline plot, is used to display 2D vector fields. This | ||
example shows a few features of the stream plot function: | ||
|
||
* Varying the color along a streamline. | ||
* Varying the density of 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? |
||
* Streamlines skipping masked regions and NaN values. | ||
* Controlling the start points of streamlines. | ||
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. See the similar comment below (in the relevant code block). |
||
""" | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
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) | ||
|
||
# Varying color along a streamline | ||
fig0, ax = plt.subplots() | ||
strm = ax.streamplot(X, Y, U, V, color=U, linewidth=2, cmap='autumn') | ||
fig0.colorbar(strm.lines) | ||
|
||
# Varying the density of streamlines | ||
fig1, (ax1, ax2) = plt.subplots(ncols=2) | ||
ax1.streamplot(X, Y, U, V, density=[0.5, 1]) | ||
|
||
# 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. I would merge this block with the previous one. I find it a bit perturbing that the previous block creates two subplots but only uses one. IMO, the two description comments may then be merged into something like: # Varying the density of streamlines (ax1) and the line width along
# a streamline (ax2). |
||
lw = 5*speed / speed.max() | ||
ax2.streamplot(X, Y, U, V, density=0.6, color='k', linewidth=lw) | ||
|
||
# Streamlines skipping masked regions and NaN values | ||
mask = np.zeros(U.shape, dtype=bool) | ||
mask[40:60, 40:60] = True | ||
U[:20, :20] = np.nan | ||
U = np.ma.array(U, mask=mask) | ||
|
||
fig2, ax = plt.subplots() | ||
ax.streamplot(X, Y, U, V, color='r') | ||
|
||
ax.imshow(-mask, extent=(-w, w, -w, w), alpha=0.5, | ||
interpolation='nearest', cmap=plt.cm.gray) | ||
|
||
# Controlling the start points of streamlines | ||
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.
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. The former refers to any streamlines, while the latter is about these streamlines. More importantly, I think it should be "starting" instead of "start". |
||
X, Y = (np.linspace(-3, 3, 100), | ||
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. Why not reuse the previous |
||
np.linspace(-3, 3, 100)) | ||
|
||
U, V = np.mgrid[-3:3:100j, 0:0:100j] | ||
|
||
seed_points = np.array([[-2, 0, 1], [-2, 0, 1]]) | ||
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 |
||
|
||
fig3, ax = plt.subplots() | ||
strm = ax.streamplot(X, Y, U, V, color=U, linewidth=2, | ||
cmap="autumn", start_points=seed_points.T) | ||
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. Being there, I would replace the double quotes with single ones (i.e. |
||
fig3.colorbar(strm.lines) | ||
|
||
ax.plot(seed_points[0], seed_points[1], 'bo') | ||
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. It might be useful to add a small comment to precise that this is some kind of an helper plot. Maybe simply: # Displaying the starting points with red symbols. Edit: start <- starting (see @QuLogic's comment above) |
||
|
||
ax.axis((-3, 3, -3, 3)) | ||
|
||
plt.show() |
This file was deleted.
This file was deleted.
This file was deleted.
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.
stream plot <-
streamplot
?