Skip to content

allow setting collection offsets to empty #22408

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ianhi
Copy link
Contributor

@ianhi ianhi commented Feb 5, 2022

PR Summary

Fixes: #22401

Importantly allows this:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

scat = ax.scatter([0,.5], [0, .5])
scat.set_offsets([[],[]])
plt.show()

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [NA] New features are documented, with examples if plot related.
  • [NA] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [NA] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [NA] Documentation is sphinx and numpydoc compliant (the docs should build without error).

modified = mcollections.Collection(
offsets=np.column_stack([[0, 1], [0, 1]])
)
modified.set_offsets([[], []])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that this should actually be column_stack and I should get rid of the transpose in the set method. Most usage will be with column_stack i suspect.

Copy link
Member

Choose a reason for hiding this comment

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

Please check what other set_offsets methods do. We should aim for consistency.

@matplotlib matplotlib deleted a comment from ianhi Feb 10, 2022
@matplotlib matplotlib deleted a comment from ianhi Feb 10, 2022
@tacaswell tacaswell added this to the v3.6.0 milestone Mar 29, 2022
(np.asarray(self.convert_xunits(offsets[:, 0]), 'float'),
np.asarray(self.convert_yunits(offsets[:, 1]), 'float')))

if offsets.shape == (2, 0):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if offsets.shape == (2, 0):
if offsets.shape == (0, 2):

Which will require some changes to the tests.

The docs say(N, 2) so this should be the degenerate case of ((N, 2), .., (2, 2), (1, 2), (0, 2)) (the (2,) case is a special case for spelling (1, 2)).

@tacaswell
Copy link
Member

Anyone can dismiss my review

@jklymak jklymak marked this pull request as draft March 30, 2022 10:52
@jklymak
Copy link
Member

jklymak commented Mar 30, 2022

Fell free to move out of draft...

@tacaswell
Copy link
Member

Looking at this again, I think my comment is still valid.

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.

[Bug]: PolyCollection set_offsets does not accept [[], []] like Line2D
6 participants