Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Streamplot supporting irregular grids with 2D x and y #12025

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

Closed
lbdreyer opened this issue Sep 5, 2018 · 11 comments
Closed

Streamplot supporting irregular grids with 2D x and y #12025

lbdreyer opened this issue Sep 5, 2018 · 11 comments
Labels
API: argument checking New feature status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action

Comments

@lbdreyer
Copy link

lbdreyer commented Sep 5, 2018

Are there any plans to support streamplotting data on irregular grids?

Currently, the streamplot documentations states:

Draws streamlines of a vector flow.

x, y : 1d arrays
    an evenly spaced grid.

If my data is on an irregular grid, I currently have to interpolate to an evenly spaced grid before I can create a streamplot. This becomes a problem when the data is very large and interpolating takes a long time.

To add more roadbloacks, my x and y values are 2D arrays. Are there plans to support 2D x and ys as input to the streamplot?

(cc @pp-mo for reference)

@pp-mo
Copy link

pp-mo commented Sep 5, 2018

Just to add to this : If I do pass 2-D x + y arrays (same shape as the u + v) ...

  • there is currently no error or warning
  • it produces a plot often quite plausibly correct ..
  • .. but on closer inspection, generally wrong (!)

That is nasty behaviour IMHO. Certainly, it had me thinking it did work, for a while ... 😊 😳 🤢

@jklymak
Copy link
Member

jklymak commented Sep 5, 2018

There is no reason that streamlines couldn’t be rewritten assuming non equal steps but it’d be a lot more code. Having it be a matrix of x and y points seems a lot harder.

@ImportanceOfBeingErnest
Copy link
Member

The streamplot example takes in 2D arrays for X,Y,U, and V. So is the example wrong? It looks good to me on first sight. Also, it produces the same output when X and Y are supplied as 1D arrays.

What is the problem with 2D input that you experience? (A code with image and a description of undesired behaviour would be helpful for that.)

Concerning the problem of irregular grids, one can always interpolate onto a regular grid first. Whether this is done by matplotlib internally or by the user externally does not make either way more or less efficient, only more convenient to use.
There are some other functions which only take regular grids. So if such internal solution is desired it might make sense to introduce it for all functions which would benefit from it.
Because matplotlib has a matplotlib.tri.LinearTriInterpolator, there would not be too much work involved. Still, because it is so easy to do the interpolation externally, I would doubt this has high priority.

@jklymak
Copy link
Member

jklymak commented Sep 5, 2018

Theoretically, the integration for making the streamplot need not be done on regularly spaced 1-d x/y grids. You just need to replace dx/dy = constant by a varying function. But the streamplot code is all written assuming dx/dy are constant; I'm not wholly convinced that the streamplot code could not be simplified a fair bit and made to accept vadying dx/dy, but thats not a project I'm going to take on.

We could always make a regular grid for users, but I'd be against us doing that versus making the user do it because gridding data often requires some artistic license, and better to let the user decide what works best for them.

@pp-mo
Copy link

pp-mo commented Oct 10, 2018

gridding data often requires some artistic license
We could always make a regular grid for users, but I'd be against us doing that versus making the user do it because gridding data often requires some artistic license

I agree. There is no such thing as a general-purpose regrid algorithm.
Though in the specific case of streamplots, there is an argument that precision is not critical, because the relationship between the original data and the plot is much less direct than other types of plot.
Compared to contouring, for example, you can't easily predict or control where it will draw the lines.

From our parochial point of view, we will generally be drawing our plots over maps with Cartopy.
So if we did use regridding, then the Iris code probably has better context for choosing a suitable target grid than matplotlib does.

However, the existing facility still seems a bit clunky to me.
At the least, when it produces a plot that is plausible but wrong, with no warning, that is a nasty gotcha !

@afvincent
Copy link
Contributor

I did not have time to read the post very carefully but there may be some implementation ideas here on unevenly gridded data (even though it is likely to be based in a rather old version of streamplot).

@liangwang0734
Copy link

liangwang0734 commented Jul 9, 2021

One possible mechanism to integrate 1-step from (x0, y0) to (x1, y1):

  • Interpolate to find the velocity (u, v) at (x0, y0).
    • Use nearest point or bilinear interpolation for any structured grid.
    • Allow passing in any user-defined interpolator for an unstructured grid.
  • Step to (x1, y1) from (x0,y0) using velocity (u,v).
    • Use any standard scheme, for example, the rk12 scheme (that streamplot is using).
  • Check the location of (x1, y1) for possible termination.

Additional processings like re-scaling the coordinates and velocities could also be important for getting optimal results.

@jonnyhtw
Copy link

jonnyhtw commented Mar 9, 2022

I'd love for this to be a possible feature, e.g. for streamlines of NEMO ocean data which has 2D lats and lons! Thanks.

@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label May 14, 2023
@github-actions github-actions bot added the status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. label Jun 14, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2023
@jhollowed
Copy link

Commenting in the hopes that this can be revisited (do issues work like that)? The limitation of evenly-spaced data for steamplot() is a pretty significant one, and it is not consistent with the rest of matplotlib. While I understand the sentiment that it's difficult to obtain a general-purpose regridding solution that won't be incompatible with at least some use cases... Matplotlib seems to already have a precedent for this, in that all of the contour functions must be applying some interpolation, no? In any case, this fix linked to by @afvincent seems so straightforward that it should be worth implementing.

@jklymak
Copy link
Member

jklymak commented Oct 15, 2024

Contour does not do any regridding. It just decides where between two consecutive points the contour should pass and doesn't care about how far apart any pair are.

Streamplot could pretty readily do the same thing. But it would need to be rewritten. As noted above, I don't think regridding is necessary or even desirable. However it is likely that a more general code would best done in c rather than Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: argument checking New feature status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action
Projects
None yet
Development

No branches or pull requests

8 participants