-
-
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
Conversation
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.
This looks mostly good, but could you merge the figures into one using several subplots?
Streamplot | ||
========== | ||
|
||
Demo of the `streamplot` function. |
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.
Can you remove this line? It is not informative.
It is because of imshow() applying an equal aspect ratio. |
I prefer the appearance of the plot with an equal aspect ratio. To get this in a desirable way, I'd used the fig = plt.figure(figsize=(7, 9))
gs = gspec.GridSpec(nrows=3, ncols=2, height_ratios=[1, 1, 2])
ax0 = fig.add_subplot(gs[0, 0])
ax1 = fig.add_subplot(gs[0, 1])
ax2 = fig.add_subplot(gs[1, 0])
ax3 = fig.add_subplot(gs[1, 1])
ax4 = fig.add_subplot(gs[2:, :])
ax4.set_aspect('equal') |
fig.colorbar(strm.lines) | ||
ax3.set_title('Controlling Starting Points') | ||
|
||
# Displaying the starting points with red symbols. |
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.
They're blue, not red.
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.
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) |
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.
If I'm not mistaken, these are the same values as the ones at the top. Maybe give the ones for ax3
a different name, then you won't need to recreate these same values again here.
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.
Oops, this comment is supposed to be about lines 62-65.
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.
No, U,V are being changed at line 47-49.
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.
In overall the PR seems nice to me, thanks for working on this @patniharshit :)! I still have some comments and suggestion. Some are taken from #8082. Again, if you are a native English speaker and disagree with some of my remarks about phrasing: drop them ;).
FWIW, switching from cmap=plt.cm.name_of_a_cmap
to cmap='name_of_a_cmap'
is just a suggestion, but I think it may make the script a (very little) bit simpler.
If I am correct, you will also need to change the references in the docs that points to the deleted files. Looking at #8082, it should now be:
- in
doc/users/screenshots.rst
, l. 74:.. plot:: mpl_examples/images_contours_and_fields/streamplot_demo.py
- in
doc/users/prev_whats_new/whats_new_1.2.rst
, l. 155:.. plot:: mpl_examples/images_contours_and_fields/streamplot_demo.py
Streamplot | ||
========== | ||
A streamplot, or streamline plot, is used to display 2D vector fields. This | ||
example shows a few features of the stream plot function: |
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?
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.
|
||
* 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
* Varying the color along a streamline. | ||
* Varying the density of streamlines. | ||
* Varying the line width along a stream line. | ||
* Controlling the start points of streamlines. |
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.
start points <- starting points?
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.
ax4.set_title('Streamline with Masking') | ||
|
||
ax4.imshow(~mask, extent=(-w, w, -w, w), alpha=0.5, | ||
interpolation='nearest', cmap=plt.cm.gray, aspect='auto') |
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.
plt.cm.gray <- 'gray'?
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.
|
||
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) |
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.
plt.cm.autumn <- 'autumn'?
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.
|
||
# Varying color along a streamline | ||
ax1 = fig.add_subplot(gs[0, 1]) | ||
strm = ax1.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=plt.cm.autumn) |
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.
plt.cm.autmn <- 'autumn'?
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.
# Controlling the starting points of the streamlines | ||
X, Y = (np.linspace(-3, 3, 100), | ||
np.linspace(-3, 3, 100)) | ||
U, V = np.mgrid[-3:3:100j, 0:0:100j] |
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.
Any reason for changing the U
, V
compared to the former streamplot_demo_start_points.py script? How bad would it be to simply re-use the same X
, Y
, U
and V
as for the other subplots? This way, you'd just need to create these (dummy) data at the beginning of the script (NB: it is already the case at ll. 18-22) and after that, the script is focused on the plotting aspect of streamplot. I think that it is also close to what @QuLogic had in mind in one of his remarks.
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.
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 comment
The 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 streamplot
. The related version of the example is only in our devdocs gallery (I guess because the PR was milestoned for 2.1 and not backported into 2.0). So I would definitively support to use the same data (built once for all at the top of the script) for all the subplots :).
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) |
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.
If one decides to always plot the same data among all the different subplots, the 5 lines above could be 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.
Huh, why is this comment here?! This is the opposite of what I had in mind ^^... Actually lines 19-23 would be the only place where I would suggest to create all the dummy data!
========== | ||
Streamplot | ||
========== | ||
A streamplot, or streamline plot, is used to display 2D vector fields. This |
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.
I am not sure that it is a mandatory requirement, but you may want to add a blank line betwenn the second =====
line and the first line of the paragraph. Maybe @NelleV would be able to confirm what SG and rST really require :).
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.
I don't think it is.
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.
Then one remaining argument in favor of adding a blank line would be consistency among our example scripts, as a lot of other examples in the docs seem to have one such blank line ;). But I am also fine with no blank line if SG and rST are OK!
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.
Blank line added to maintain consistency among all examples.
# Displaying the starting points with blue symbols. | ||
ax3.plot(seed_points[0], seed_points[1], 'bo') | ||
|
||
ax3.axis((-3, 3, -3, 3)) |
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.
I forgot to comment on this one during my review, sorry. Is this line really needed (I do not see the equivalent for the previous subplots)? If indeed it is and one actually uses the same dummy data accross all the subplots, I would then rather suggest using ax3.axis((-w, w, -w, w))
instead (if I understand correctly the purpose of this line).
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.
Other subplots were going from -3 to 3 but this one was not, so probably this line was put there to have uniformity in all plots. I have kept this. But it can be deleted considering this is supposed to be an example, thus it should use minimal code to achieve target.
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.
You are right. Due to the reduced amount of streamlines that are plotted, it seems like the axis is not exactly the same as for the other plots. So it might be wiser to keep it :). 👍 for the new version ax3.axis((-w, w, -w, w))
.
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.
A few remaining comments, among which my biggest one will be to use the same dummy data (defined at the beginning of the script) for all the subplots. But apart from that, the PR starts to look really good to me :).
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) |
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.
Huh, why is this comment here?! This is the opposite of what I had in mind ^^... Actually lines 19-23 would be the only place where I would suggest to create all the dummy data!
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
ax4 = fig.add_subplot(gs[2:, :]) | ||
ax4.streamplot(X, Y, U, V, color='r') | ||
ax4.set_title('Streamline with Masking') |
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.
Plural form (as there are several streamlines), or "Streamplot with Masking"?
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.
Changed to "Streamplot with masking".
========== | ||
|
||
A stream plot, or stream line plot, is used to display 2D vector fields. This | ||
example shows a few features of the stream plot function: |
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.
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 streamplot
function and not to a stream plot. I guess I was not clear enough: it was actually the meaning of my previous comment ^^. However, for the other utterances of "stream plot"/"stream line," I will let a native English speaker (who may be you!) decide if it is better than "streamplot"/"streamline" or not.
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.
I think generally, "streamline" is a word and "streamplot" is not, unless you're referring to the function itself (as in this case.)
@NelleV Should this be renamed as |
I don't think example deletion should be backported, so I've upped the milestone. |
Travis failures seem unrelated (they are about |
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.
Last tiny nitpicking, based on @QuLogic comment about writing “streamline” with a single word (basically it reverts some of the changes made by a530e79).
Besides, pinging @NelleV about the other @QuLogic's comment: should this be renamed as plot_something.py
(for Sphinx gallery sake IIUC)?
Apart from that, the new version of the example script looks fine, thanks @patniharshit :)!
Question to core devs who may pass by: if @patniharshit is comfortable with git, would it be relevant to rebase, and squash a bit the commits?
Streamplot | ||
========== | ||
|
||
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
All done.
A stream plot, or stream line plot, is used to display 2D vector fields. This | ||
example shows a few features of the streamplot function: | ||
|
||
* Varying the color along a stream line. |
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.
streamline
example shows a few features of the streamplot function: | ||
|
||
* Varying the color along a stream line. | ||
* Varying the density of stream lines. |
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.
streamlines
|
||
* Varying the color along a stream line. | ||
* Varying the density of stream lines. | ||
* Varying the line width along a stream line. |
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.
streamline
* Varying the color along a stream line. | ||
* Varying the density of stream lines. | ||
* Varying the line width along a stream line. | ||
* Controlling the starting points of stream lines. |
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.
streamlines
* Varying the density of stream lines. | ||
* Varying the line width along a stream line. | ||
* Controlling the starting points of stream lines. | ||
* Stream lines skipping masked regions and NaN values. |
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.
Streamlines
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.
LGTM :).
A few questions to other devs:
- should this be renamed as “plot_something.py” for Sphinx gallery sake? (@NelleV , pinging our SG expert if she is around)
- should it be rebased and some of the commits squashed if @patniharshit is comfortable with git?
@afvincent my answer is "yes" to both of those. |
3302135
to
7baa01e
Compare
Renamed, rebased and commits squashed. |
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.
Minor fixes needed. Apart from that, the other Travis failures seems to be spurious ones.
@@ -152,7 +152,7 @@ In addition to simply plotting the streamlines of the vector field, | |||
line widths of the streamlines to a separate parameter, such as the speed or | |||
local intensity of the vector field. | |||
|
|||
.. plot:: mpl_examples/images_contours_and_fields/streamplot_demo_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 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.
doc/users/screenshots.rst
Outdated
@@ -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:: mpl_examples/images_contours_and_fields/streamplot_demo_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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Oh forgot this. Will do it asap. |
LGTM. Thanks @patniharshit :) ! |
Ugh, I was going to merge this, but it looks like it needs a rebase with that sphinx-gallery PR merged. |
I'm going to attempt a rebase and merge |
fe5dc72
to
d56b5ce
Compare
Okay, that looks like it worked, but since it's the first time I've done a rebase and force-push I'll wait for CI to pass before merging. |
I see that the current version of the |
I see no errors in the latest CI build; note that examples from |
How can I also replicate it? I am spending time on fixing the error from |
Replicate what? There is no error in |
I get the following error:
|
The syntax for |
@pssk1988 -- are you working with a matplotlib installed from the latest github master? |
@phobson : I don't think so :/ I will look for using the github matplotlib. |
I am really sorry to bother you all without using the github version of matplotlib. Now it works fine. |
Based on discussion in #8155 a new pull request combining work with #8082.
Refs #7956