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

Add dataarray scatter with 3d support #4909

Merged
merged 57 commits into from
Jul 17, 2021

Conversation

Illviljan
Copy link
Contributor

@Illviljan Illviljan commented Feb 14, 2021

  • Closes #xxxx
  • Tests added
  • Passes pre-commit run --all-files
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

Add scatter plots for dataarrays. Then later remove the dataset version and replace it with a thin wrapper in a similar fashion to #4820.

New stuff:

  • Legend now displays colors and sizes in a similar fashion to Seaborn.
  • New parameter z which allows 3d scatter plots.

Example:
Using ds = xr.tutorial.scatter_example_dataset():
image

@pep8speaks
Copy link

pep8speaks commented Feb 14, 2021

Hello @Illviljan! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-06-30 16:24:25 UTC

@Illviljan Illviljan marked this pull request as draft February 14, 2021 11:32
@dcherian
Copy link
Contributor

that size legend is nice! I wonder if we should put both legends outside the axis using figlegend?

@Illviljan
Copy link
Contributor Author

figlegend doesn't work that great within subplots though right? When I tried subplots the legends were just added on top of each other. I think ax.legend is a better, but it seems rather difficult to fit it outside. I've tried a few variants with bbox_to_anchor but it quickly gets non robust when deviating from the defaults.

I've been trying to merge the legends together though . So then the legend will attempt to find the best places automatically so that helps a little bit:
image

@Illviljan Illviljan mentioned this pull request Apr 20, 2021
5 tasks
@dcherian dcherian requested a review from TomNicholas May 13, 2021 17:44
@Illviljan
Copy link
Contributor Author

If it seems safer we could make this non-public, da.plot._scatter?
This is not being tested as properly as ds.plot.scatter at the moment so I might've missed some edge cases, but once we use the same code path for both of them this should be more reliable.

Copy link
Member

@TomNicholas TomNicholas left a comment

Choose a reason for hiding this comment

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

@Illviljan this is an excellent PR!

It would be nice to factor out some of the helper functions into plot.utils or elsewhere, and especially to use the @_plot2d decorator, but there is not need to squeeze that into this PR.

If you're worried about this not being fully robust until other plotting methods are condensed into one code path then I would just suggest not making it callable as a plot method yet (or renaming to _scatter as you suggested). But I also think it's fine to release as is.

@Illviljan Illviljan closed this Jun 24, 2021
@Illviljan Illviljan reopened this Jun 24, 2021
@Illviljan
Copy link
Contributor Author

It would be nice to factor out some of the helper functions into plot.utils or elsewhere, and especially to use the @_plot2d decorator, but there is not need to squeeze that into this PR.

Thanks, @TomNicholas. My original plan and attempts was to use _plot2d. But because the return type originally was so different to the other plot functions (list of pathcollections vs pathcollections) it was impossible to use it without pretty much if-casing the entire _plot2d. I also feel _plot2d makes it pretty hard to read and understand the code.

I think it might be doable now that the function only returns pathcollection. I'll take a stab at that again in a different PR.

If you're worried about this not being fully robust until other plotting methods are condensed into one code path then I would just suggest not making it callable as a plot method yet (or renaming to _scatter as you suggested). But I also think it's fine to release as is.

Ok, I'll rename it to a private name. But I think it's good that it's still callable, so that others can easily try it out without any promises that the API will stay the same. I was also considering changing/removing some variable names related to legend compared to the dataset version, so it's good to let that it be private until that's been figured out.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 30, 2021

Unit Test Results

         6 files  ±0           6 suites  ±0   52m 40s ⏱️ ±0s
16 178 tests ±0  14 447 ✔️ ±0  1 730 💤 ±0  1 ❌ ±0 
90 264 runs  ±0  82 111 ✔️ ±0  8 147 💤 ±0  6 ❌ ±0 

For more details on these failures, see this check.

Results for commit 4cde773. ± Comparison against base commit 4cde773.

♻️ This comment has been updated with latest results.

@Illviljan Illviljan closed this Jun 30, 2021
@Illviljan Illviljan reopened this Jun 30, 2021
@Illviljan Illviljan closed this Jun 30, 2021
@Illviljan Illviljan reopened this Jun 30, 2021
@TomNicholas TomNicholas added the plan to merge Final call for comments label Jun 30, 2021
@TomNicholas TomNicholas mentioned this pull request Jul 8, 2021
8 tasks
@dcherian
Copy link
Contributor

Thanks @Illviljan We can keep iterating on this per Tom's comments.

@dcherian dcherian merged commit 4cde773 into pydata:main Jul 17, 2021
st-bender added a commit to st-bender/xarray that referenced this pull request Aug 10, 2021
* main: (31 commits)
  Refactor index vs. coordinate variable(s) (pydata#5636)
  pre-commit: autoupdate hook versions (pydata#5685)
  Flexible Indexes: Avoid len(index) in map_blocks (pydata#5670)
  Speed up _mapping_repr (pydata#5661)
  update the link to `scipy`'s intersphinx file (pydata#5665)
  Bump styfle/cancel-workflow-action from 0.9.0 to 0.9.1 (pydata#5663)
  pre-commit: autoupdate hook versions (pydata#5660)
  fix the binder environment (pydata#5650)
  Update api.rst (pydata#5639)
  Kwargs to rasterio open (pydata#5609)
  Bump codecov/codecov-action from 1 to 2.0.2 (pydata#5633)
  new blank whats-new for v0.19.1
  v0.19.0 release notes (pydata#5632)
  remove deprecations scheduled for 0.19 (pydata#5630)
  Make typing-extensions optional (pydata#5624)
  Plots get labels from pint arrays (pydata#5561)
  Add to_numpy() and as_numpy() methods (pydata#5568)
  pin fsspec (pydata#5627)
  pre-commit: autoupdate hook versions (pydata#5617)
  Add dataarray scatter with 3d support (pydata#4909)
  ...
dcherian added a commit to kmsquire/xarray that referenced this pull request Aug 11, 2021
* upstream/main: (31 commits)
  Refactor index vs. coordinate variable(s) (pydata#5636)
  pre-commit: autoupdate hook versions (pydata#5685)
  Flexible Indexes: Avoid len(index) in map_blocks (pydata#5670)
  Speed up _mapping_repr (pydata#5661)
  update the link to `scipy`'s intersphinx file (pydata#5665)
  Bump styfle/cancel-workflow-action from 0.9.0 to 0.9.1 (pydata#5663)
  pre-commit: autoupdate hook versions (pydata#5660)
  fix the binder environment (pydata#5650)
  Update api.rst (pydata#5639)
  Kwargs to rasterio open (pydata#5609)
  Bump codecov/codecov-action from 1 to 2.0.2 (pydata#5633)
  new blank whats-new for v0.19.1
  v0.19.0 release notes (pydata#5632)
  remove deprecations scheduled for 0.19 (pydata#5630)
  Make typing-extensions optional (pydata#5624)
  Plots get labels from pint arrays (pydata#5561)
  Add to_numpy() and as_numpy() methods (pydata#5568)
  pin fsspec (pydata#5627)
  pre-commit: autoupdate hook versions (pydata#5617)
  Add dataarray scatter with 3d support (pydata#4909)
  ...
@Illviljan Illviljan deleted the Illviljan-dataarray_scatter branch March 13, 2024 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plan to merge Final call for comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants