Skip to content

[ENH]: More control of "axis planes" on 3D axes #23216

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
tdelcourt opened this issue Jun 7, 2022 · 5 comments
Closed

[ENH]: More control of "axis planes" on 3D axes #23216

tdelcourt opened this issue Jun 7, 2022 · 5 comments

Comments

@tdelcourt
Copy link

Problem

Duplicate from stackoverflow 72375427 .

When plotting 2D scatter data on a 3D scatter plot (eg as in the example code from matplotlib website, which incidentally shows the problematic behaviour as the sin curve is obviously off by a bit), the 2D data floats "on top" or "alongside" of the 2D face it is supposed to be placed upon and therefore gives the impression to be wrongly plotted. For example, using this to show the projection of dots from the 3D space to 2D planes (3 plot faces) gives the impression that the dots are not at the correct position, because of the parallax (see plot linked below).

3D plot with 2D plots on sides, as produced by above code
3D plot with 2D plots on sides, as expected

I cannot get the planes to exactly be positioned at a specified coordinate. Setting the x_lim, y_lim and z_lim parameters only slightly improves this, but there is still a slight, seemingly random, margin added beyond the axes limits (contrary to what happens in 2D plots).

Proposed solution

I may have missed the option to do this. But it would be nice to have the possibility to overrule the automatic setting of the position of the edge planes so that setting the x_lim, y_lim and z_lim parameters fixes the planes to those specified values (for instance, or another extra parameter).

Another solution based on generating the 2D graphs as images and adding them to the 3D plot could potentially work, but probably is a messy hack more than a solution.

@jklymak
Copy link
Member

jklymak commented Jun 7, 2022

As of 3.5.0 we have computed_zorder: https://matplotlib.org/stable/api/_as_gen/mpl_toolkits.mplot3d.axes3d.Axes3D.html#mpl-toolkits-mplot3d-axes3d-axes3d. which should allow you to set this manually.

@tacaswell tacaswell changed the title [ENH]: [ENH]: More control of "axis planes" on 3D axes Jun 8, 2022
@tacaswell
Copy link
Member

@tdelcourt Is that title an accurate summary of your request?

@tdelcourt
Copy link
Author

As of 3.5.0 we have computed_zorder: https://matplotlib.org/stable/api/_as_gen/mpl_toolkits.mplot3d.axes3d.Axes3D.html#mpl-toolkits-mplot3d-axes3d-axes3d. which should allow you to set this manually.

I've tried setting computed_zorder to False and setting zorders (see the following changes to the code below), but this does not change anything at all. There still is the same very slight margin added on all axes even when setting axes limits manually and setting zorders (the order of which doesn't change the behaviour). I'm using matplotlib 3.5.1.

ax = fig.add_subplot(projection='3d', computed_zorder=False)
[...]
# Plot 3D scatter plot (zorder=1 to be first plotted)
ax.scatter(x_vals, y_vals, z_vals, color=colours, s=16, marker=".", depthshade=False, zorder=1)
[...]
# Plot 2D plots, higher zorder to draw after 3D plot
# X-Y plot
ax.scatter(xs=x_vals, ys=y_vals, zs=z_lim[0], color=colours, s=8, marker=".", zorder=4)
# X-Z plot
ax.scatter(xs=x_vals, ys=y_lim[1], zs=z_vals, color=colours, s=8, marker=".", zorder=3)
# Y-Z plot
ax.scatter(xs=x_lim[0], ys=y_vals, zs=z_vals, color=colours, s=8, marker=".", zorder=2)

@tdelcourt Is that title an accurate summary of your request?
Yes, thanks :-)

@scottshambaugh
Copy link
Contributor

I believe this is a duplicate of #18052 ?

@scottshambaugh
Copy link
Contributor

Closing as a duplicate of #18052

@tdelcourt thank you for the report and please let me know if that other issue does not capture the scope of what you're asking for!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants