Skip to content

Standardize edge-on axis locations when viewing primary 3d axis planes #23644

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
Aug 19, 2022

Conversation

scottshambaugh
Copy link
Contributor

@scottshambaugh scottshambaugh commented Aug 17, 2022

PR Summary

For the special cases of looking at the 3d axes in the 6 primary view planes (defined in the docs in #23600), draw the axes such that one is on the bottom edge and the other intersects at the low value (ie the intersection is at the origin for these examples). This blends smoothly when rotating the axes manually, since we are only looking at the epsilon case.

Code to generate these plots is the same as here.

Before:
before

After:
image

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).

@scottshambaugh scottshambaugh force-pushed the 3d_view_axes_alignmnet branch from ca1af31 to 7e5c070 Compare August 17, 2022 05:15
@scottshambaugh scottshambaugh changed the title Put edge-on axes on left and right when viewing 3d axis planes Put edge-on axes on left and bottom when viewing 3d axis planes Aug 17, 2022
@scottshambaugh scottshambaugh changed the title Put edge-on axes on left and bottom when viewing 3d axis planes Put edge-on axes on left and bottom when viewing primary 3d axis planes Aug 17, 2022
@scottshambaugh scottshambaugh marked this pull request as ready for review August 17, 2022 05:17
@scottshambaugh scottshambaugh force-pushed the 3d_view_axes_alignmnet branch 2 times, most recently from e34be8a to 7fc0b7d Compare August 17, 2022 05:32
@QuLogic
Copy link
Member

QuLogic commented Aug 17, 2022

Would it make sense for the negative planes to swap left/right edges? So that the lines always go through 0.0?

@scottshambaugh
Copy link
Contributor Author

scottshambaugh commented Aug 17, 2022

I had thought about that and thought it might be less useful when the axes are shifted away from 0, but am open to that too. Either is an improvement over the current.

@scottshambaugh scottshambaugh marked this pull request as draft August 17, 2022 18:20
@scottshambaugh scottshambaugh changed the title Put edge-on axes on left and bottom when viewing primary 3d axis planes Standardize edge-on axis locations when viewing primary 3d axis planes Aug 17, 2022
@scottshambaugh scottshambaugh force-pushed the 3d_view_axes_alignmnet branch from 7fc0b7d to 14bd014 Compare August 18, 2022 00:17
@scottshambaugh
Copy link
Contributor Author

scottshambaugh commented Aug 18, 2022

@QuLogic trying it out, I like the layout of your suggestion just as much and it probably makes more intuitive sense. Simplifies the logic too. I replaced the image in the top post so you can look at it

@scottshambaugh
Copy link
Contributor Author

scottshambaugh commented Aug 18, 2022

Just for fun, here's an "unfolded" view of a 3D plot that might be useful to people/worth sticking in docs.

import matplotlib.pyplot as plt

def annotate_axes(ax, text, fontsize=18):
    ax.text(x=0.5, y=0.5, z=0.5, s=text,
            va="center", ha="center", fontsize=fontsize, color="black")

# (view, (elev, azim, roll))
views = [( 'XY', ( 90, -90, 0)), 
         ( 'XZ', (  0, -90, 0)),  
         ( 'YZ', (  0,   0, 0)), 
         ('-XY', (-90,  90, 0)), 
         ('-XZ', (  0,  90, 0)),
         ('-YZ', (  0, 180, 0))]

layout = [['XY', '.',  'L',  '.'],
          ['XZ','YZ','-XZ','-YZ',],
          ['.',  '.','-XY',  '.',]]
fig, axd = plt.subplot_mosaic(layout, subplot_kw={'projection': '3d'})
for i in range(len(axd) - 1):
    plane = views[i][0]
    axd[plane].set_xlabel('x')
    axd[plane].set_ylabel('y')
    axd[plane].set_zlabel('z')
    axd[plane].set_proj_type('ortho')
    axd[plane].view_init(elev=views[i][1][0], azim=views[i][1][1], roll=views[i][1][2])

    label = f'{plane}\n{views[i][1]}'
    annotate_axes(axd[plane], label, fontsize=14)

label = 'matplotlib Axes3D Primary View Planes\nax.view_init(elev, azim, roll)'
annotate_axes(axd['L'], label, fontsize=18)
axd['L'].set_axis_off()
plt.tight_layout()

image

@QuLogic
Copy link
Member

QuLogic commented Aug 18, 2022

OK, sorry one more question; can the third Axis also always appear around 0/0?

@scottshambaugh
Copy link
Contributor Author

scottshambaugh commented Aug 18, 2022

Unfortunately not, to do so would require having the backing planes in the +-XY and +-YZ views blocking either the plot volume or the axis spines. Here are the plots with the same axis locations rotated slightly off-angle to help visualize this.

I mean, I supposed you could carve out blocking views for specifically these angles, but then it's a discontinuous flash when rotating the plots manually or programmatically. And I think it'd be pretty ugly to implement.

image

Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@QuLogic QuLogic merged commit 2e8231f into matplotlib:main Aug 19, 2022
@QuLogic QuLogic added this to the v3.6.0 milestone Aug 19, 2022
@QuLogic QuLogic mentioned this pull request Sep 9, 2022
2 tasks
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.

3 participants