Skip to content

add docstring for set_3d_properties for PatchCollection3d #19572

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

Closed
wants to merge 1 commit into from

Conversation

ianhi
Copy link
Contributor

@ianhi ianhi commented Feb 24, 2021

PR Summary

  1. Added a docstring
  2. Gave zdir a default to be consistent with the rest of the file.

PR Checklist

  • Is Flake 8 compliant (run flake8 on changed files to check).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

I'm sceptical on the default zdir.

It works when using the default zdir='z' at artist creation time, but can be surprising otherwise. Note that not specifying zdir in set_3d_properties in the second plot rotates the data.

import matplotlib.pyplot as plt
import numpy as np

fig, (ax1, ax2) = plt.subplots(1, 2, subplot_kw={'projection': '3d'}, figsize=(12, 6))

x = np.linspace(-1, 1, 51)
y = 1 - x**2
z = np.exp(-np.abs(2*x))

# plot a reference line and a second one with half scaling
# in the 3rd dim. using set_3d_properties()
ax1.plot(x, y, z)
l, = ax1.plot(x, y, z, '--')
l.set_3d_properties(0.5*z)

# same but using zdir='x' for the original data
ax2.plot(x, y, z, zdir='x')
l, = ax2.plot(x, y, z, '--', zdir='x')
l.set_3d_properties(0.5*z)

plt.show()

grafik

More generally, this whole API is awkward and inconsistent between different Artists.

I'd say that set_3d_properties() should be a private helper. Unfortunately, for most Artists it's currently the only way to update 3d data. But splitting the update in two functions is insane for a user-facing API. Text3D does it almost right:

  • It has set_position_3d()
  • It internally stores self._dir_vec so that zdir is optional in set_position_3d()

IMHO the correct way forward would be to create similar data setters for all Artists.
The minimal step would be to store self._dir_vec in set_3d_projection and make zdir there default to None.

Comment on lines +468 to +470
Update the z values of the offsets. If there are more XY points in
the offsets than there are Z points then points without a Z offset
will not be drawn.
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
Update the z values of the offsets. If there are more XY points in
the offsets than there are Z points then points without a Z offset
will not be drawn.
Update the offset values for the 3rd dimension. If there are more
XY points in the offsets than given here, these additional points
are not drawn.

Hope this makes it a little more clear. Z is a little ambiguous.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 that's definitely an improvement. My only question is what tense is the docstring speaking in? Since the draw will happen after this function is called I used will not be but are switches to the present tense which I found confusing. Not a big deal either way.

@timhoffm
Copy link
Member

Removed documentation tag, because as of now this also changes the function signature.

@ianhi
Copy link
Contributor Author

ianhi commented Feb 27, 2021

IMHO the correct way forward would be to create similar data setters for all Artists.

I don't think this is exactly what you mean but see also: #19573

I'm sceptical on the default zdir.

It works when using the default zdir='z' at artist creation time, but can be surprising otherwise. Note that not specifying zdir in set_3d_properties in the second plot rotates the data.

That's a compelling example. Note that many of the other artists set_3d_properties do default to zdir='z' so perhaps it is those that should be changed?

@ianhi
Copy link
Contributor Author

ianhi commented Feb 27, 2021

Text3D does it almost right:

Why almost? What more would you want there? Privatizing set_3d_properties?

@ianhi
Copy link
Contributor Author

ianhi commented Feb 28, 2021

For now I removed the addition of default argument for zdir. But something probably should be done about the inconsistency of the various set_3d_properties function signatures. Though what is not clear to me.

@ianhi
Copy link
Contributor Author

ianhi commented Feb 28, 2021

One other thing that this PR should definitely do make sure all of the set_3d_properties have docstrings (ideally similar ones) so that I don't become culpable for the aforementioned inconsistency.

But for that I think there should be a consistent phrase used to describe zdir. I didn't add one because I'm confused by what it should be, and as I noted in #19573 (comment) there are several different descriptions of it already floating around.

@timhoffm
Copy link
Member

Text3D does it almost right:

Why almost? What more would you want there? Privatizing set_3d_properties?

IIRC that and not having a default zdir='z' on set_3d_properties().

@timhoffm
Copy link
Member

But something probably should be done about the inconsistency of the various set_3d_properties function signatures. Though what is not clear to me.

Let's make them private first. Otherwise, this will become quite a song and dance with deprecations.

But that'S is for a separate PR.

But for that I think there should be a consistent phrase used to describe zdir. I didn't add one because I'm confused by what it should be, and as I noted in #19573 (comment) there are several different descriptions of it already floating around.

We promote artists from 2D to 3D by adding a dimension. zdir defines how that is done. The effect is most obvious for artists that do not have a real third dimension, e.g. the bars in https://matplotlib.org/devdocs/gallery/mplot3d/bars3d.html. The zdir is the normal to the plane in which this 2D-representation is drawn. For bar(x, y, z) the first two values are interpreted in this 2D subspace, the third value defines the position of that 2D-image along zdir. That means that for zdir='x', the values x, y are on the axis-plane yz.

Special case Line3D: As this is not pseudo-3D, there should usually not be a reason to use a different zdir. But it might be helpful if you plot it along with other data, e.g. bar(x, y, z, zdir='x'); plot(x, y, z, zdir='x').

Special case Text3D: The text direction is in the plane normal to zdir. The characters are rendered along the text direction, but always facing the camera; i.e. you cannot look at the text "from the side/back".

Copy link

Since this Pull Request has not been updated in 60 days, it has been marked "inactive." This does not mean that it will be closed, though it may be moved to a "Draft" state. This helps maintainers prioritize their reviewing efforts. You can pick the PR back up anytime - please ping us if you need a review or guidance to move the PR forward! If you do not plan on continuing the work, please let us know so that we can either find someone to take the PR over, or close it.

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Nov 17, 2023
@scottshambaugh
Copy link
Contributor

The docstring here was added in #23536, so closing this PR. Thank you for the initial work on this!

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.

The various set_3d_properties() methods are undocumented.
4 participants