Skip to content

Uncertainty ellipses for quiver #16750

Closed as not planned
Closed as not planned

Description

@tobiscode

Hi all,

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.

Cross-link to Cartopy issue no. 1487

Activity

  1. jklymak commented on Mar 12, 2020

    @jklymak
    Member
  2. tobiscode commented on Mar 12, 2020

    @tobiscode
    Author

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

  3. jklymak commented on Mar 12, 2020

    @jklymak
    Member

    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.

  4. tobiscode commented on Mar 12, 2020

    @tobiscode
    Author

    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.

  5. added
    Community support
    on Mar 12, 2020
  6. jklymak commented on Mar 12, 2020

    @jklymak
    Member

    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.

  7. ImportanceOfBeingErnest commented on Mar 12, 2020

    @ImportanceOfBeingErnest
    Member

    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.

  8. greglucas commented on Mar 13, 2020

    @greglucas
    Contributor

    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?

  9. tacaswell commented on Mar 13, 2020

    @tacaswell
    Member

    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.

  10. added this to the milestone on Mar 13, 2020
  11. tobiscode commented on Mar 13, 2020

    @tobiscode
    Author

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

  12. tobiscode commented on Mar 14, 2020

    @tobiscode
    Author

    I've made a Stack Overflow post, let's see what it brings.

  13. modified the milestones: , needs sorting on Oct 6, 2022
  14. github-actions commented on Oct 11, 2023

    @github-actions

    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!

  15. added
    status: inactive
    on Oct 11, 2023
  16. timhoffm commented on Oct 11, 2023

    @timhoffm
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Community supportstatus: inactive

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions