10000 Specify ticks and axis label positions for 3D plots by scottshambaugh · Pull Request #25830 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Specify ticks and axis label positions for 3D plots #25830

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 6 commits into from
Aug 2, 2023

Conversation

scottshambaugh
Copy link
Contributor
@scottshambaugh scottshambaugh commented May 7, 2023

PR summary

Closes #10767

This allows for specific control of where the ticks and axis labels are positioned for 3D plots. This is robust to rotating the plots.

There is some refactoring work done here to break out drawing different elements into functions to enable the change, and it made me realize how much axis3d needs some work. Would like to get these upper/lower axes independently customizable, but for now this is a step in the right direction even if it doesn't solve everything.

import matplotlib.pyplot as plt
positions = ['default', 'upper', 'lower', 'both', 'none']
fig, axs = plt.subplots(1, 5, subplot_kw={'projection': '3d'})
for ax, pos in zip(axs.flatten(), positions):
    for axis in ax.xaxis, ax.yaxis, ax.zaxis:
        axis.set_label_position(pos)
        axis.set_ticks_position(pos)
    ax.set(xlabel='x', ylabel='y', zlabel='z', title=pos)

image

PR checklist

@scottshambaugh scottshambaugh force-pushed the 3d_axis_positions branch 2 times, most recently from d28327e to a81c1f0 Compare May 7, 2023 23:22
@QuLogic QuLogic added this to the v3.8.0 milestone May 8, 2023
@YongYahn
Copy link

It is recommended that when drawing 3D graphics, the default Z-axis is on the left, in line with the diagram drawn by matlab.

@scottshambaugh
Copy link
Contributor Author
scottshambaugh commented May 12, 2023

Hi @YongYahn, the intent of this PR is to allow you to customize the appearance to do that! However changing the default would change the look of existing plots from past versions, and we try to avoid those sorts of backwards-incompatible changes.

@scottshambaugh scottshambaugh force-pushed the 3d_axis_positions branch 2 times, most recently from 7000028 to c76a9f0 Compare May 14, 2023 23:59
Copy link
Member
@oscargus oscargus left a comment

Choose a reason for hiding this comment

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

Looks good! Nice to have it a bit refactored so that it is easier to see what each part does.

Some comment to slightly improve the code efficiency/readability.

@scottshambaugh scottshambaugh force-pushed the 3d_axis_positions branch 2 times, most recently from 653c73a to 8bc0dcb Compare July 7, 2023 21:59
@scottshambaugh
Copy link
Contributor Author

Bump on this, would be nice to get in 3.8.0 with one approval already.

Fix tick directions

Make tickdirs work all the time

More tickdir tweaks

Code review comments

Apply suggestions from code review

Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>

Code review suggestions

linting
Code review commits

Test image for axis positions
Copy link
Member
@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

Both 'lower' and 'both' do not have any ticks or labels in the what's new example. Also, you've added a test image, but no test?

@scottshambaugh scottshambaugh force-pushed the 3d_axis_positions branch 2 times, most recently from 6eb7b43 to d883ffe Compare August 1, 2023 15:07
@scottshambaugh
Copy link
Contributor Author
scottshambaugh commented Aug 1, 2023

Thanks @QuLogic, it seems like a commit got dropped somewhere. Should be fixed up now.

image

< 8000 input type="hidden" data-csrf="true" name="authenticity_token" value="SmTwUJrq4Q9Bcm5WKQFYjMPx9m99Ye5lrCRcEL6XtmMGLSB2Zo9MOWp3HlQNd8frGCcKywxjwD2Do4zTVtX1yQ==" />

Copy link
Member
@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

I see some of the commits are specifically split out, but others are just clean up; do you want to rebase and squash some of them together?

@scottshambaugh scottshambaugh force-pushed the 3d_axis_positions branch 2 times, most recently from e69e199 to 724e80c Compare August 2, 2023 02:47
@scottshambaugh
Copy link
Contributor Author

Squashed a bunch of them, feel free to squash further on merge. Thanks!

@QuLogic QuLogic merged commit b5149fd into matplotlib:main Aug 2, 2023
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.

ENH: Possibility to decide tick and label position in mplot3d
5 participants
0