Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Merged
merged 4 commits into from
Apr 12, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Merge all figure in streamplot examples in one plot
  • Loading branch information
patniharshit authored and dstansby committed Apr 12, 2017
commit bf2b43b5aad4d9a9486587834792bfcd6e4e509e
79 changes: 79 additions & 0 deletions 79 examples/images_contours_and_fields/streamplot_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"""
==========
Streamplot
==========
A streamplot, or streamline plot, is used to display 2D vector fields. This
Copy link
Contributor

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 :).

Copy link
Member

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.

Copy link
Contributor

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!

Copy link
Contributor Author

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.

example shows a few features of the stream plot function:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stream plot <- streamplot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

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.

Copy link
Member

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.)


* Varying the color along a streamline.
* Varying the density of streamlines.
* Varying the line width along a stream line.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stream line <- streamline?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

streamline

* Controlling the start points of streamlines.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start points <- starting points?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* Streamlines skipping masked regions and NaN values.
"""
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)

fig = plt.figure()

# Varying density along a streamline
ax0 = fig.add_subplot(321)
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plt.cm.autmn <- 'autumn'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

fig.colorbar(strm.lines)
ax1.set_title('Varying color')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Varying Color?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


# Varying line width along a streamline
ax2 = fig.add_subplot(323)
lw = 5*speed / speed.max()
ax2.streamplot(X, Y, U, V, density=0.6, color='k', linewidth=lw)
ax2.set_title('Varying Line Width')

# 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]
Copy link
Contributor

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.

Copy link
Contributor Author

@patniharshit patniharshit Mar 25, 2017

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 -
figure_1-2

Copy link
Contributor

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 :).

seed_points = np.array([[-2, -1, 0, 1, 2, -1], [-2, -1, 0, 1, 2, 2]])

ax3 = fig.add_subplot(324)
strm = ax3.streamplot(X, Y, U, V, color=U, linewidth=2,
cmap=plt.cm.autumn, start_points=seed_points.T)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plt.cm.autumn <- 'autumn'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

fig.colorbar(strm.lines)
ax3.set_title('Controlling Starting Points')

# Displaying the starting points with red symbols.
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

ax3.plot(seed_points[0], seed_points[1], 'bo')

ax3.axis((-3, 3, -3, 3))
Copy link
Contributor

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).

Copy link
Contributor Author

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.

Copy link
Contributor

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)).


# Create a mask
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)
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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!


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)

ax4 = fig.add_subplot(325)
ax4.streamplot(X, Y, U, V, color='r')
ax4.set_title('Streamline with Masking')
Copy link
Contributor

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"?

Copy link
Contributor Author

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".


ax4.imshow(~mask, extent=(-w, w, -w, w), alpha=0.5,
interpolation='nearest', cmap=plt.cm.gray, aspect='auto')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plt.cm.gray <- 'gray'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


plt.tight_layout()
plt.show()
33 changes: 0 additions & 33 deletions 33 examples/images_contours_and_fields/streamplot_features.py

This file was deleted.

29 changes: 0 additions & 29 deletions 29 examples/images_contours_and_fields/streamplot_masking.py

This file was deleted.

28 changes: 0 additions & 28 deletions 28 examples/images_contours_and_fields/streamplot_start_points.py

This file was deleted.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.