The Wayback Machine - https://web.archive.org/web/20230707142324/https://github.com/matplotlib/matplotlib/pull/25830
Skip to content
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

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

Open
wants to merge 12 commits into
base: main
from

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
Contributor

@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.

lib/mpl_toolkits/mplot3d/axis3d.py Show resolved Hide resolved
lib/mpl_toolkits/mplot3d/axis3d.py Outdated Show resolved Hide resolved
lib/mpl_toolkits/mplot3d/axis3d.py Show resolved Hide resolved
lib/mpl_toolkits/mplot3d/axis3d.py Outdated Show resolved Hide resolved
lib/mpl_toolkits/mplot3d/axis3d.py Outdated Show resolved Hide resolved
lib/mpl_toolkits/mplot3d/axis3d.py Outdated Show resolved Hide resolved
lib/mpl_toolkits/mplot3d/axis3d.py Outdated Show resolved Hide resolved
lib/mpl_toolkits/mplot3d/axis3d.py Outdated Show resolved Hide resolved
lib/mpl_toolkits/mplot3d/axis3d.py Outdated Show resolved Hide resolved
lib/mpl_toolkits/mplot3d/axis3d.py Outdated Show resolved Hide resolved
lib/mpl_toolkits/mplot3d/axis3d.py Outdated Show resolved Hide resolved
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
4 participants