Way to specify viewpoint distance in 3d plots
Asked Answered
T

1

3

I am working on an animation of a 3D plot using mpl_toolkits.mplot3d (Matplotlib 3.6.3) and need to set the view distance.

It seems that earlier versions of Matplotlib allowed the elevation, azimuth, and distance of the viewpoint "camera" to be set for 3D plots using methods like this:

ax.elev = 45
ax.azim = 10
ax.dist = 2

but the distance attribute appears to have been deprecated for some reason:

Warning (from warnings module):
    ax.dist = 2
MatplotlibDeprecationWarning: The dist attribute was deprecated in Matplotlib 3.6 and will be removed two minor releases later.

This still runs, but the output plots have all sorts of visual artifacts that only go away if I shut off the axes with ax.set_axis_off().

Is there an equivalent means of setting the viewpoint distance to zoom in on a 3D data set in 3.6.3?

Tripos answered 17/1, 2023 at 12:50 Comment(0)
H
3

According to the documentation, you now need to use the zoom argument of set_box_aspect:

ax.set_box_aspect(None, zoom=2)

Where the first argument is the aspect ratio. Use None to use the default values.

Hotchkiss answered 17/1, 2023 at 13:7 Comment(5)
That did the trick. Thanks. I was also going to ask how to set the box aspect. The documentation for the aspect ratio says it is float, but it must be a vector e.g. aspect_ratio = (1,1,1) sets the axes equal in 3D.Tripos
For some reason the zoom parameter is not documented.Charissacharisse
Also this might seem obvious, but large dist zooms out; large zoom zooms in. It would be useful to know the exact relation between the two.Sapphira
@DanielTchoń To zoom out, you can set the zoom value between 0 and 1.Meza
@enj Yes; what I meant is if would be useful to know the exact conversion function between old dist and new zoom.Sapphira

© 2022 - 2024 — McMap. All rights reserved.