You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've recently noted that even after significant searching, I did not find a Python plotting tool or package that enables plotting uncertainty/error ellipses when plotting arrows/vectors with quiver. This is especially useful when plotting displacement fields with associated uncertainties (example), or complex numbers with correlated errors, etc.
Currently, the only way to do this for mapping purposes is to rely on GMT's psvelo, which has been and is used extensively, but requires the full GMT installation and usage via the command-line. Their Python implementation, PyGMT is still in its early stages and it is unknown how long the integration into a Python interface will take (plus, it uses its own backend, so most of Matplotlib's other powerful features wouldn't be usable anyway). Similarly, Cartopy does not have a dedicated quiver analog.
I am not aware of any tools that do this for complex numbers. In both cases, I welcome workarounds, fixes or other packages that implement this functionality and that I missed during my search.
I can imagine that if someone understands how transformations work in Matplotlib/Cartopy, it shouldn't be too hard to add the creation of an ellipses when drawing the arrows (but that is sadly not me).
In my view, offering this functionality would provide a huge boost in usability of Matplotlib and Python in general for many scientific fields.
I did; the problem is however getting the the location of where to put the ellipse. I couldn't find an easy way to get the location of the tip of the arrows plotted by quiver. (Let alone one that would respect zoom-ins in the figure, or geographic transforms like the ones used in Cartopy - at least from my limited understanding of how that works.)
OK, that is likely non-trivial for general uses of quiver, but the documentation of quiver is pretty clear on where the end of the quiver will be, particularly if you use a scientifically meaningful scale units like xy, and making an ellipse in the same units should be relatively straight forward.
If it is easy, I haven't been able to figure it out. Usually, the units are not 'xy', as X,Y can be a position, and U,V are vectors (wind directions, velocities).
Also, I tried around using the returned quiver object, and using q.scale did not relate X,Y to U,V. If you know how to do this, please share, it would be very helpful.
So the answer to this issue is that the built-in capability does not exist to do this automatically in general.
If quivers are in xy units, and the angle is xy, then I believe the end of the quiver is at (x + u / s, y + v / s). Otherwise the end of the quivers are at some position on the canvas determined by either the size of the axes or the figure. If you size your quivers that way, it should still be possible to place an Ellipse at the end, but it will be a lot more complicated.
If you are asking for help getting this to work, I suggest you post this on https://discourse.matplotlib.org or stack overflow with a self-contained example of how you are calling quiver. If discussion there progresses to the point that this should be a feature request, you could open a new issue with a detailed proposal.
This does sound like a good problem that is non-trivial. However, I don't think it should be an extra function in either Cartopy or Matplotlib. It would probably be best implemented as a helper function that would be a great addition to the examples gallery.
Another complication with going towards a map would be what coordinate frame the ellipse is in. Do you want the ellipse transformed/stretched with the map transforms, or to appear as an ellipse in axes coordinates and only the center location moved relative to the map?
Thanks for all your input. I'll see when I can come up with the time to make a tractable MWE to post on Stack Overflow (and would cross-reference that here).
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!
Activity
jklymak commentedon Mar 12, 2020
Did you see the gallery example about this? https://matplotlib.org/devdocs/gallery/statistics/confidence_ellipse.html
tobiscode commentedon Mar 12, 2020
I did; the problem is however getting the the location of where to put the ellipse. I couldn't find an easy way to get the location of the tip of the arrows plotted by quiver. (Let alone one that would respect zoom-ins in the figure, or geographic transforms like the ones used in Cartopy - at least from my limited understanding of how that works.)
jklymak commentedon Mar 12, 2020
OK, that is likely non-trivial for general uses of quiver, but the documentation of
quiveris pretty clear on where the end of the quiver will be, particularly if you use a scientifically meaningful scale units likexy, and making an ellipse in the same units should be relatively straight forward.tobiscode commentedon Mar 12, 2020
If it is easy, I haven't been able to figure it out. Usually, the units are not
'xy', as X,Y can be a position, and U,V are vectors (wind directions, velocities).Also, I tried around using the returned
quiverobject, and usingq.scaledid not relate X,Y to U,V. If you know how to do this, please share, it would be very helpful.jklymak commentedon Mar 12, 2020
So the answer to this issue is that the built-in capability does not exist to do this automatically in general.
If quivers are in
xyunits, and the angle isxy, then I believe the end of the quiver is at(x + u / s, y + v / s). Otherwise the end of the quivers are at some position on the canvas determined by either the size of the axes or the figure. If you size your quivers that way, it should still be possible to place anEllipseat the end, but it will be a lot more complicated.If you are asking for help getting this to work, I suggest you post this on https://discourse.matplotlib.org or stack overflow with a self-contained example of how you are calling quiver. If discussion there progresses to the point that this should be a feature request, you could open a new issue with a detailed proposal.
ImportanceOfBeingErnest commentedon Mar 12, 2020
I think I remember someone once asking to collect problems that are hard to solve in matplotlib. This is one perfect candidate for that collection.
greglucas commentedon Mar 13, 2020
This does sound like a good problem that is non-trivial. However, I don't think it should be an extra function in either Cartopy or Matplotlib. It would probably be best implemented as a helper function that would be a great addition to the examples gallery.
An additional example for transforms with ellipses that I've used when plotting multiple ellipses on maps with Cartopy (and therefore using non-trivial transforms) is: https://matplotlib.org/3.1.1/gallery/shapes_and_collections/ellipse_collection.html
Another complication with going towards a map would be what coordinate frame the ellipse is in. Do you want the ellipse transformed/stretched with the map transforms, or to appear as an ellipse in axes coordinates and only the center location moved relative to the map?
tacaswell commentedon Mar 13, 2020
This also seems perfect as a third-party package where you can make the assumptions you would need to make to make this a tractable problem.
tobiscode commentedon Mar 13, 2020
Thanks for all your input. I'll see when I can come up with the time to make a tractable MWE to post on Stack Overflow (and would cross-reference that here).
tobiscode commentedon Mar 14, 2020
I've made a Stack Overflow post, let's see what it brings.
github-actions commentedon Oct 11, 2023
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!
timhoffm commentedon Oct 11, 2023
This feature is complex and quite specific. It is beyond the scope of the main library and would best be implemented as a third party package.