Skip to content
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

Dataset.plot.quiver #4407

Merged
merged 28 commits into from
Feb 19, 2021
Merged

Dataset.plot.quiver #4407

merged 28 commits into from
Feb 19, 2021

Conversation

dcherian
Copy link
Contributor

@dcherian dcherian commented Sep 5, 2020

  • Closes Add Dataset.plot.quiver #4373
  • Tests added
  • Passes isort . && black . && mypy . && flake8
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

I could use some help with adding tests and parameter checking if someone wants to help :)

import numpy as np
import xarray as xr

ds = xr.Dataset()
ds.coords["x"] = ("x", np.arange(10))
ds.coords["y"] = ("y", np.arange(20))
ds.coords["t"] = ("t", np.arange(4))
ds["u"] = np.sin((ds.x - 5) / 5) * np.sin((ds.y - 10) / 10)
ds["v"] = np.sin((ds.x - 5) / 5) * np.cos((ds.y - 10) / 10)

ds = ds * 2*np.cos((ds.t) * 2 * 3.14 /0.75)

ds["u"].attrs["units"] = "m/s"
ds["mag"] = np.hypot(ds.u, ds.v)

ds.mag.plot(col="t", x="x")

fg = ds.plot.quiver(x="x", y="y", u="u", v="v", col="t", hue="mag")

image
image

@dcherian
Copy link
Contributor Author

This is ready for a review. I don't I can fix the quiverkey without matplotlib/matplotlib#18530 . This is still useful for a quick look at the data.

@dcherian dcherian requested a review from mathause January 20, 2021 00:23
Copy link
Collaborator

@mathause mathause left a comment

Choose a reason for hiding this comment

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

Looks good. The plotting code is not getting simpler 🙃 but it's so useful!

  • Why is scale required for facetgrid and not for a single panel?
  • Should it emit a Warning/ Error if u or v are given and funcname != "quiver"

@dcherian
Copy link
Contributor Author

Why is scale required for facetgrid and not for a single panel?

matplotlib will make a nice choice for the single panel. With facetgrid, the scale will be different for each panel if we don't specify it. And i had trouble porting the matplotlib algorithm. We can always add this in the future.

Should it emit a Warning/ Error if u or v are given and funcname != "quiver"

Good idea. Done.

* upstream/master:
  speed up the repr for big MultiIndex objects (pydata#4846)
  dim -> coord in DataArray.integrate (pydata#3993)
  WIP: backend interface, now it uses subclassing  (pydata#4836)
  weighted: small improvements (pydata#4818)
  Update related-projects.rst (pydata#4844)
  iris update doc url (pydata#4845)
  Faster unstacking (pydata#4746)
  Allow swap_dims to take kwargs (pydata#4841)
  Move skip ci instructions to contributing guide (pydata#4829)
  fix issues in drop_sel and drop_isel (pydata#4828)
  Bugfix in list_engine (pydata#4811)
  Add drop_isel (pydata#4819)
  Fix RST.
  Remove the references to `_file_obj` outside low level code paths, change to `_close` (pydata#4809)
self.figlegend = None
self.quiverkey = None
self.cbar = None
Copy link
Contributor Author

Choose a reason for hiding this comment

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

technically backwards incompatible but I'm not sure it affects anyone.

@dcherian dcherian requested a review from mathause February 11, 2021 14:21
Copy link
Collaborator

@mathause mathause left a comment

Choose a reason for hiding this comment

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

Looks good (but I don't have experience with plt.quiver).

dcherian and others added 3 commits February 12, 2021 07:04
* upstream/master:
  FIX: h5py>=3 string decoding (pydata#4893)
  Update matplotlib's canonical (pydata#4919)
  Adding vectorized indexing docs (pydata#4711)
  Allow fsspec URLs in open_(mf)dataset (pydata#4823)
  Fix typos in example notebooks (pydata#4908)
  pre-commit autoupdate CI (pydata#4906)
  replace the ci-trigger action with a external one (pydata#4905)
  Update area_weighted_temperature.ipynb (pydata#4903)
  hide the decorator from the test traceback (pydata#4900)
  Sort backends (pydata#4886)
  Compatibility with dask 2021.02.0 (pydata#4884)
@dcherian
Copy link
Contributor Author

I'll merge on Friday if there are no more comments.

@dcherian dcherian merged commit 070d815 into pydata:master Feb 19, 2021
@dcherian dcherian deleted the dataset/quiver branch February 19, 2021 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Dataset.plot.quiver
2 participants