'Changing axis scale in 3d plot with Sympy

What is the simplest way to change the axis scales or axis limits of a 3D plot with Sympy? For instance, if I want to plot a torus:

from sympy import *
from sympy.plotting import *

u, v = symbols('u v')
p = plot3d_parametric_surface((5 + cos(u))*cos(v), (5 + cos(u))*sin(v), sin(u),
                              (u, 0, 2*pi), (v, 0, 2*pi))

we get

enter image description here

But I want something like:

enter image description here

I did this last picture with numpy/matplotlib.pyplot but I want to do it as simple as possible with Sympy...



Solution 1:[1]

You'd have to access the Matplotlib's axis object created by Sympy, like this:

from sympy import *
from sympy.plotting import *
import numpy as np

u, v = symbols('u v')
p = plot3d_parametric_surface((5 + cos(u))*cos(v), (5 + cos(u))*sin(v), sin(u),
                              (u, 0, 2*pi), (v, 0, 2*pi))
p._backend.ax[0].set_box_aspect(aspect = (1,1,0.2))
ticks = np.linspace(-1, 1, 3)
p._backend.ax[0].set_zticks(ticks, ticks)
# show the figure
p._backend.fig

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Davide_sd