-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Allow changing the vertical axis in 3d plots #19873
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
Allow changing the vertical axis in 3d plots #19873
Conversation
I'm sure I'm simply missing the point here, but... If I have a 2-D axes, and do The larger complaint that our camera angle manipulation is not very flexible is valid, but I don't see that this is a fix for that. |
Ooops, sorry I should have read the original proposal (ahem, it actually helps to put more description with the PR if possible). This appears to be tied only to |
It's a draft for a reason. :) But maybe I should start copy/pasting the issue texts in here as well. The background is that I want to make it easy jumping between This is the issues I've managed to figure out:
Issues I haven't figured out yet:
|
Appreciate that it is still draft, but this could get messy fast, so we wanted to give some feedback before you spent too much time on it ;-) |
In today's dev call, we have decided that The semantics should be that for Note: I did not yet look into the implementation. But I assume to achieve this, one should rotate about the (1, 1, 1) direction by 120° / 240°. |
This is how it looks like at the moment: plt.figure()
for i, vert_a in enumerate(["z", "y", "x"]):
ax = plt.subplot(1, 3, i+1, projection="3d")
pc = ax.scatter(X, Y, Z, c=c)
ax.view_init(azim=0, elev=0, vertical_axis=vert_a)
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z") And with default angles: plt.figure()
for i, vert_a in enumerate(["z", "y", "x"]):
ax = plt.subplot(1, 3, i+1, projection="3d")
pc = ax.scatter(X, Y, Z, c=c)
ax.view_init(vertical_axis=vert_a)
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z") |
Check matplotlib/lib/mpl_toolkits/mplot3d/axis3d.py Line 232 in fe1acd6
unfortunately, this code is quite ancient and not one of the clearest. |
It is a little bit further down, here:
https://github.com/matplotlib/matplotlib/blob/fe1acd6c2d97fbea04610af05ac18ec42427bd26/lib/mpl_toolkits/mplot3d/axis3d.py#L303
One of my first major contributions. There is no theory. There is no
"logic". It was me just sitting down with a pad of paper and recording the
state of different variables at this area of the code until I found a
pattern.
…On Sun, Apr 11, 2021 at 6:59 PM Tim Hoffmann ***@***.***> wrote:
Where in the code does matplotlib determine where the axis values are
positioned? I can't find it, any ideas are appreciated:
Check
https://github.com/matplotlib/matplotlib/blob/fe1acd6c2d97fbea04610af05ac18ec42427bd26/lib/mpl_toolkits/mplot3d/axis3d.py#L232
unfortunately, this code is quite ancient and not one of the clearest.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#19873 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHF6HK5QXS7AR43QMDSH3TIISUXANCNFSM42NJPOFA>
.
|
Gotten the black axis lines to match for each vertical axis. It's a little hardcoded unfortunately but I haven't managed to figure out anything better, any ideas here are appreciated. import matplotlib.pyplot as plt
import numpy as np
x = np.array([0, 1, 2, 4])
y = np.array([5, 10])
z = np.array([100, 150, 200])
X, Y, Z = np.meshgrid(*[x, y, z], indexing="ij")
c = np.arange(0, X.size)
plt.figure()
for j, (a, e) in enumerate([(0, 0), (30, 30)]):
for i, vert_a in enumerate(["z", "y", "x"]):
ax = plt.subplot(2, 3, j * 3 + 1 + i, projection="3d")
pc = ax.scatter(X, Y, Z, c=c)
ax.view_init(azim=a, elev=e, vertical_axis=vert_a)
ax.set_title(f"azim={a}, elev={e}, vertical_axis='{vert_a}'")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z") Now I see that the ticks are not aligned correctly so that's the next thing to fix. It'll likely be something similarly hardcoded though, unless it's possible to make use of the gridlines somehow to determine the direction of the ticks? |
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, this should look approximately the same no matter which axis is vertical, assuming you didn't plot anything or add any axis labels. Would it make sense to use check_figures_equal
to compare each pair, instead?
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@QuLogic Eventhough I don't see any difference between the different vertical axes I don't think the plots are exactly equal still, because |
Ah right, I forgot about those. I wonder if those colours should also be juggled, with one consistently indicating the 'bottom'. But I'm not exactly sure what the meaning of those colours was intended to mean in the first place. |
@QuLogic Here's how it looks like with I'm leaning towards not changing this. I like that the colors continue to match, it seems like a nice trick to quickly tell where the axes has been rotated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This look great! IMHO close to the finish line.
This needs a rebase now that that's been merged. |
Are you able to rebase this? Now the unrelated changes moved to the other PR appear in two different commits. Or this could be squash merged. |
No clue how to do that, so I suggest squash merge. :) |
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@Illviljan thanks for fiddling out the details and going through the somewhat tedious review process. This is a great improvement! We hope to hear from you again. 👍 |
* allow changing the vertical axis * change aspect to follow vertical axis, * add projection test * Update axes3d.py * Update test_mplot3d.py * axis lines behaves the same as default * Update axis3d.py * Rotate ticks correctly. * undo comments for unchanged code * generalize slightly * add tickdir test * Update lib/mpl_toolkits/mplot3d/axes3d.py Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> * Update axes3d.py * move func to method * Update lib/mpl_toolkits/mplot3d/axes3d.py Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> * Update lib/mpl_toolkits/mplot3d/axes3d.py Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> * Update lib/mpl_toolkits/tests/test_mplot3d.py Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> * Update lib/mpl_toolkits/mplot3d/axis3d.py Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> * Update lib/mpl_toolkits/mplot3d/axes3d.py Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> * Update lib/mpl_toolkits/mplot3d/axes3d.py Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com> * docstring styling * Add test for axis lines. * Update axis3d.py * Add whats new * filename typo * Update lib/mpl_toolkits/mplot3d/axis3d.py Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com> * Update lib/mpl_toolkits/tests/test_mplot3d.py Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com> * Update lib/mpl_toolkits/mplot3d/axes3d.py Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com> * Update lib/mpl_toolkits/mplot3d/axis3d.py Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com> * Use _api.check_getitem * Update lib/mpl_toolkits/tests/test_mplot3d.py Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com> * Update lib/mpl_toolkits/tests/test_mplot3d.py Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com> Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
PR Summary
Add support for 3d plots to align the y axis vertically instead of the z axis by setting
ax.view_init(vertical_axis="y")
.Closes #19791.
Requires #20242
Background
I have a hard time grasping what happens when jumping between 2d and 3d scatters because the y changes from the vertical direction to the depth direction.
Results
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).