10000 Add set_data_3d and get_data_3d to Line3d by Raab70 · Pull Request #10111 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add set_data_3d and get_data_3d to Line3d #10111

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

Merged
merged 5 commits into from
Jan 8, 2019

Conversation

Raab70
Copy link
Contributor
@Raab70 Raab70 commented Dec 27, 2017

PR Summary

Fixes #8914 by adding set_data_3d and get_data_3d methods to Line3D. This allows for setting and getting of 3d data without overriding the widely used set_data and get_data methods.

> from mpl_toolkits.mplot3d import Axes3D
> x = [0, 1]
> y = [0, 1]
> z = [0, 1]
> fig = plt.figure()
> ax = fig.add_subplot(111, projection='3d')
> line = ax.plot(x,y,z)[0]
> line.get_data_3d()
(array([0, 1]), array([0, 1]), array([0, 1]))
> line.set_data_3d([0,2], [0,2], [0,2])
> line.get_data_3d()
([0, 2], [0, 2], [0, 2])

I looked for testing and documentation and did not see any testing or documentation related to Line3D would require updating. Please let me know if this is incorrect.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

"""
Return the xdata, ydata, zdata.
"""
return self._verts3d
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to un-juggle the order of the data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It probably should. We're calling set_3d_properties with no zdir so we shouldn't do any juggling but the user could change the zdir, I'll probably also allow an optional kwarg to allow the user to also set zdir right from set_data_3d.

Copy link
Member

Choose a reason for hiding this comment

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

Both should probably get the zdir kwarg?

Copy link
Member

Choose a reason for hiding this comment

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

The juggle axis feature is for converting a 2D object into 3D. It essentially states which dimension is going to be a constant. It is not applicable here.

Copy link
Member
@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

👍 Looks like a reasonable feature and something we should support.

This needs a test (a round-trip test showing you can set (x, y, z) and then get the values back out is enough, I do not think this needs an image test) and a whats_new entry (so people know this exists).

Could you also change the docstrings to numpydoc format (but not going to block PR on that because the rest of this module is not converted yet)?

@tacaswell tacaswell added this to the v2.2 milestone Jan 2, 2018
@tacaswell tacaswell requested a review from WeatherGod January 2, 2018 00:58
x, y, z = args

self.set_xdata(x)
self.set_ydata(y)
Copy link
Member

Choose a reason for hiding this comment

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

This is incorrect. set_xdata() and set_ydata() are for the 2D projected values. self._verts3d is just a tuple of the 3 1D arrays.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, fair enough. Using this method is very suggestive due to

def set_3d_properties(self, zs=0, zdir='z'):
xs = self.get_xdata()
ys = self.get_ydata()
try:
# If *zs* is a list or array, then this will fail and
# just proceed to juggle_axes().
zs = float(zs)
zs = [zs for x in xs]
except TypeError:
pass
self._verts3d = juggle_axes(xs, ys, zs, zdir)
self.stale = True

but on a bit closer inspection it seems that these methods are used in the 2D class -> 3D class upcasting, not as a standard part of the setup.

"""
Return the xdata, ydata, zdata.
"""
return self._verts3d
Copy link
Member

Choose a reason for hiding this comment

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

The juggle axis feature is for converting a 2D object into 3D. It essentially states which dimension is going to be a constant. It is not applicable here.

@Raab70
Copy link
Contributor Author
Raab70 commented Feb 12, 2018

I think I've addressed all issues here but if anyone wants to let me know why Travis is complaining I'd love to hear. From the log it looks like it failed in lib/matplotlib/tests/test_compare_images.py:222 which is a file not changed in this PR.

@WeatherGod
Copy link
Member
WeatherGod commented Feb 12, 2018 via email

@Raab70
Copy link
Contributor Author
Raab70 commented Feb 12, 2018

Thanks for the tip @WeatherGod, that seems to have fixed Travis but broken circleci...

Again, definitely not something changed in this PR.

Warning, treated as error:
/home/circleci/project/lib/matplotlib/image.py:docstring of matplotlib.image.NonUniformImage.set_interpolation:10:Inline substitution_reference start-string without end-string.

@Raab70
Copy link
Contributor Author
Raab70 commented Jun 11, 2018

Ping @tacaswell and @WeatherGod, rebasing on master seems to have fixed it this time.

@themightyoarfish
Copy link

Can this be merged?

if len(args) == 1:
self._verts3d = args[0]
else:
self._verts3d = args
Copy link
Member

Choose a reason for hiding this comment

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

I think you need to add self.stale = True here.

@WeatherGod
Copy link
Member

ping @tacaswell , the tests were added

Copy link
Member
@ImportanceOfBeingErnest ImportanceOfBeingErnest left a comment

Choose a reason for hiding this comment

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

This is a useful and frequently demanded feature. The PR in the current state is complete afaict.

@tacaswell tacaswell merged commit c044780 into matplotlib:master Jan 8, 2019
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.

line3D set_data only takes in x and y data
6 participants
0