| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
This looks mostly good, but could you merge the figures into one using several subplots?
Sorry, something went wrong.
| Streamplot | ||
| ========== | ||
|
|
||
| Demo of the `streamplot` function. |
There was a problem hiding this comment.
Can you remove this line? It is not informative.
Sorry, something went wrong.
Sorry, something went wrong.
|
It is because of imshow() applying an equal aspect ratio. |
Sorry, something went wrong.
Sorry, something went wrong.
|
I prefer the appearance of the plot with an equal aspect ratio. To get this in a desirable way, I'd used the gridspec module (it's always nice to show that off in other places) 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') |
Sorry, something went wrong.
Sorry, something went wrong.
| fig.colorbar(strm.lines) | ||
| ax3.set_title('Controlling Starting Points') | ||
|
|
||
| # Displaying the starting points with red symbols. |
There was a problem hiding this comment.
They're blue, not red.
Sorry, something went wrong.
There was a problem hiding this comment.
Done.
Sorry, something went wrong.
| 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.
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.
Sorry, something went wrong.
There was a problem hiding this comment.
Oops, this comment is supposed to be about lines 62-65.
Sorry, something went wrong.
There was a problem hiding this comment.
No, U,V are being changed at line 47-49.
Sorry, something went wrong.
There was a problem hiding this comment.
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:
Sorry, something went wrong.
| 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.
stream plot <- streamplot?
Sorry, something went wrong.
There was a problem hiding this comment.
Done.
Sorry, something went wrong.
|
|
||
| * 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.
stream line <- streamline?
Sorry, something went wrong.
There was a problem hiding this comment.
Done.
Sorry, something went wrong.
| * 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.
start points <- starting points?
Sorry, something went wrong.
There was a problem hiding this comment.
Done.
Sorry, something went wrong.
| 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.
plt.cm.gray <- 'gray'?
Sorry, something went wrong.
There was a problem hiding this comment.
Done.
Sorry, something went wrong.
|
|
||
| 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.
plt.cm.autumn <- 'autumn'?
Sorry, something went wrong.
There was a problem hiding this comment.
Done.
Sorry, something went wrong.
|
|
||
| # 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.
plt.cm.autmn <- 'autumn'?
Sorry, something went wrong.
There was a problem hiding this comment.
Done.
Sorry, something went wrong.
| # 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.
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.
Sorry, something went wrong.
There was a problem hiding this comment.
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 -

Sorry, something went wrong.
There was a problem hiding this comment.
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 :).
Sorry, something went wrong.
| 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.
If one decides to always plot the same data among all the different subplots, the 5 lines above could be deleted.
Sorry, something went wrong.
There was a problem hiding this comment.
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!
Sorry, something went wrong.
| ========== | ||
| Streamplot | ||
| ========== | ||
| A streamplot, or streamline plot, is used to display 2D vector fields. This |
There was a problem hiding this comment.
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 :).
Sorry, something went wrong.
There was a problem hiding this comment.
I don't think it is.
Sorry, something went wrong.
There was a problem hiding this comment.
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!
Sorry, something went wrong.
There was a problem hiding this comment.
Blank line added to maintain consistency among all examples.
Sorry, something went wrong.
| # 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.
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).
Sorry, something went wrong.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
There was a problem hiding this comment.
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)).
Sorry, something went wrong.
There was a problem hiding this comment.
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 :).
Sorry, something went wrong.
| 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.
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!
Sorry, something went wrong.
| 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.
Varying Color?
Sorry, something went wrong.
There was a problem hiding this comment.
Done.
Sorry, something went wrong.
|
|
||
| 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.
Plural form (as there are several streamlines), or "Streamplot with Masking"?
Sorry, something went wrong.
There was a problem hiding this comment.
Changed to "Streamplot with masking".
Sorry, something went wrong.
| ========== | ||
|
|
||
| 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.
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.
Sorry, something went wrong.
There was a problem hiding this comment.
I think generally, "streamline" is a word and "streamplot" is not, unless you're referring to the function itself (as in this case.)
Sorry, something went wrong.
|
@NelleV Should this be renamed as plot_something.py? |
Sorry, something went wrong.
|
I don't think example deletion should be backported, so I've upped the milestone. |
Sorry, something went wrong.
|
Travis failures seem unrelated (they are about test_mixedsubplots…) |
Sorry, something went wrong.
There was a problem hiding this comment.
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?
Sorry, something went wrong.
| Streamplot | ||
| ========== | ||
|
|
||
| A stream plot, or stream line plot, is used to display 2D vector fields. This |
There was a problem hiding this comment.
streamline
Sorry, something went wrong.
There was a problem hiding this comment.
All done.
Sorry, something went wrong.
| 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.
streamline
Sorry, something went wrong.
| 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.
streamlines
Sorry, something went wrong.
|
|
||
| * 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.
streamline
Sorry, something went wrong.
| * 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.
streamlines
Sorry, something went wrong.
| * 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.
Streamlines
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM :).
A few questions to other devs:
Sorry, something went wrong.
|
@afvincent my answer is "yes" to both of those. |
Sorry, something went wrong.
|
Renamed, rebased and commits squashed. |
Sorry, something went wrong.
There was a problem hiding this comment.
Minor fixes needed. Apart from that, the other Travis failures seems to be spurious ones.
Sorry, something went wrong.
| 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.
'streamplot_demo.py' should be changed into 'plot_streamplot.py', shouldn't it?
Sorry, something went wrong.
There was a problem hiding this comment.
Done.
Sorry, something went wrong.
| 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.
Here too, 'streamplot_demo.py' should be changed into 'plot_streamplot.py', shouldn't it?
Sorry, something went wrong.
There was a problem hiding this comment.
Done.
Sorry, something went wrong.
|
Oh forgot this. Will do it asap. |
Sorry, something went wrong.
|
Ugh, I was going to merge this, but it looks like it needs a rebase with that sphinx-gallery PR merged. |
Sorry, something went wrong.
|
I'm going to attempt a rebase and merge |
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
|
I see that the current version of the plot_streamplot.py from repo is giving errors/not executing. |
Sorry, something went wrong.
|
I see no errors in the latest CI build; note that examples from master are not guaranteed to work on any released version. |
Sorry, something went wrong.
|
How can I also replicate it? I am spending time on fixing the error from master. Could you please let me know, how to perform such a check? |
Sorry, something went wrong.
|
Replicate what? There is no error in master. |
Sorry, something went wrong.
|
I get the following error: Traceback (most recent call last):
File "plot_streamplot.py", line 50, in <module>
cmap='autumn', start_points=seed_points.T)
File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1814, in inner
return func(ax, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_axes.py", line 4464, in streamplot
zorder=zorder)
File "/usr/lib/python2.7/dist-packages/matplotlib/streamplot.py", line 140, in streamplot
sp2[:, 0] += np.abs(x[0])
ValueError: operands could not be broadcast together with shapes (6,) (100,) (6,)
|
Sorry, something went wrong.
|
The syntax for streamline says that x and y should be 1D array and u and v as 2D array. However in the example, both x and y are made as 2D grids using np.mgrid. When they are made just as 1D array, the issue is fixed. |
Sorry, something went wrong.
|
@pssk1988 -- are you working with a matplotlib installed from the latest github master? |
Sorry, something went wrong.
|
@phobson : I don't think so :/ I will look for using the github matplotlib. |
Sorry, something went wrong.
|
I am really sorry to bother you all without using the github version of matplotlib. Now it works fine. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Based on discussion in #8155 a new pull request combining work with #8082.
Refs #7956