Skip to content

Add optional quiverkey to motion field quiver plots - #584

Open
A2ELAOUDI wants to merge 1 commit into
pySTEPS:v1.xfrom
A2ELAOUDI:feat/169-quiverkey
Open

A2ELAOUDI wants to merge 1 commit into
pySTEPS:v1.xfrom
A2ELAOUDI:feat/169-quiverkey

Conversation

@A2ELAOUDI

Copy link
Copy Markdown

Closes #169

quiver() (and motion_plot() with plot_type="quiver") now takes an optional quiverkey_kwargs dict. If it is given, a reference arrow is added with matplotlib's quiverkey(). Any quiverkey() argument can be passed (X, Y, U, label, labelpos, coordinates, color, ...). With an empty dict you get the defaults:

  • U = largest plotted vector, rounded to one significant digit (falls back to 1 if the field is all zero/NaN)
  • label = "<U> px timestep$^{-1}$", as suggested in the issue, so it works for any data resolution
  • placed just above the top right corner of the axes (X=0.75, Y=1.02, coordinates="axes", labelpos="E")

The default (quiverkey_kwargs=None) adds no key, so existing plots and the return value (the axes) don't change. Passing quiverkey_kwargs with a streamplot raises a ValueError.

Example:

quiver(V, geodata=metadata, step=25, quiverkey_kwargs={"U": 5, "label": "5 px/5min"})

Testing: added tests in pysteps/tests/test_plt_motionfields.py for no key by default, default U/label/position, U rounding (including zero and NaN fields), custom kwargs and the streamplot error. They fail on master and pass with this change. black --check . passes.

Note: locally two existing tests in that file fail on master too, unrelated to this change (missing MeteoSwiss example data, and the synthetic streamplot case hitting matplotlib 3.11's "'y' must be strictly increasing" check).

Add a quiverkey_kwargs argument to motionfields.quiver and motion_plot.
When given, a reference arrow is drawn with matplotlib's quiverkey. By
default its length is the largest plotted vector rounded to one
significant digit and the label uses px timestep^-1 units.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Options for quiverkey when plotting motion fields

1 participant