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

scatter plot by order of the first appearance of hue #4723

Merged
merged 11 commits into from
Jan 13, 2021

Conversation

keewis
Copy link
Collaborator

@keewis keewis commented Dec 22, 2020

As suggested by @ahuang11, this uses pandas.unique(x.flatten()) instead of numpy.unique(x) to preserve the order (numpy.unique sorts its output). Apparently we could also use the return_index option of numpy.unique to reconstruct the order, but that seems involve sorting the indices:

def _unique(array):
    array = array.flatten()
    _, indices = np.unique(array, return_index=True)
    return array[np.sort(indices)]

I'm not sure how to add tests for this change.

@keewis keewis changed the title scatter plot by order of first appearance scatter plot by order of the first appearance of the hue Dec 22, 2020
@keewis keewis changed the title scatter plot by order of the first appearance of the hue scatter plot by order of the first appearance of hue Dec 22, 2020
Copy link
Contributor

@dcherian dcherian left a comment

Choose a reason for hiding this comment

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

For a test we could create a legend, loop over handles in the legend and check the labels?

xarray/plot/dataset_plot.py Show resolved Hide resolved
xarray/plot/dataset_plot.py Show resolved Hide resolved
@keewis keewis closed this Jan 6, 2021
@keewis keewis reopened this Jan 6, 2021
@keewis
Copy link
Collaborator Author

keewis commented Jan 11, 2021

the upstream-dev failure can be ignored, I guess (the next run of the scheduled CI should open a issue to track this).

Should we merge this PR?

xarray/plot/dataset_plot.py Show resolved Hide resolved
Copy link
Contributor

@dcherian dcherian left a comment

Choose a reason for hiding this comment

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

Thanks @keewis

@keewis keewis force-pushed the scatter-legend-labels branch from b025776 to f60db74 Compare January 13, 2021 22:42
@keewis
Copy link
Collaborator Author

keewis commented Jan 13, 2021

thanks for the reviews, @dcherian, @shoyer.

@keewis keewis merged commit 747fe26 into pydata:master Jan 13, 2021
@keewis keewis deleted the scatter-legend-labels branch January 13, 2021 23:02
dcherian added a commit to TomNicholas/xarray that referenced this pull request Jan 18, 2021
* upstream/master: (342 commits)
  fix decode for scale/ offset list (pydata#4802)
  Expand user dir paths (~) in open_mfdataset and to_zarr. (pydata#4795)
  add a version info step to the upstream-dev CI (pydata#4815)
  fix the ci trigger action (pydata#4805)
  scatter plot by order of the first appearance of hue (pydata#4723)
  don't skip the scheduled CI (pydata#4806)
  coords: retain str dtype (pydata#4759)
  Fix interval labels with units (pydata#4794)
  Always force dask arrays to float in missing.interp_func (pydata#4771)
  Print number of variables in repr (pydata#4762)
  install conda as a library in the minimum dependency check CI (pydata#4792)
  Migrate CI from azure pipelines to GitHub Actions (pydata#4730)
  use conda.api instead of parallel calls to the conda binary (pydata#4775)
  Speed up missing._get_interpolator (pydata#4776)
  Remove special case in guess_engines (pydata#4777)
  improve typing of OrderedSet (pydata#4774)
  CI: ignore some warnings (pydata#4773)
  DOC: update hyperlink for xskillscore (pydata#4778)
  drop support for python 3.6 (pydata#4720)
  Trigger upstream CI on cron schedule (by default) (pydata#4729)
  ...
dcherian added a commit to dcherian/xarray that referenced this pull request Feb 3, 2021
* master: (458 commits)
  Add units if "unit" is in the attrs. (pydata#4850)
  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)
  fix decode for scale/ offset list (pydata#4802)
  Expand user dir paths (~) in open_mfdataset and to_zarr. (pydata#4795)
  add a version info step to the upstream-dev CI (pydata#4815)
  fix the ci trigger action (pydata#4805)
  scatter plot by order of the first appearance of hue (pydata#4723)
  ...
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.

Wrong hue assignment in scatter plot
3 participants