3D 图中的垂直夸大
Vertical exaggeration in 3D plots
我正在绘制一个 3D 圆柱体 space 并且想夸大 z 轴以拉伸图像。
这是我使用的代码的简化版本和相应的图像。我已经将图形大小更改为我需要的大小,如何拉伸实际绘制的图像以便夸大 z 轴?
def data_for_cylinder_along_z(center_x,center_y,radius,Dto,Dfrom):
z = np.linspace(Dfrom, Dto, 50)
theta = np.linspace(0, 2*np.pi, 50)
theta_grid, z_grid=np.meshgrid(theta, z)
x_grid = radius*np.cos(theta_grid) + center_x
y_grid = radius*np.sin(theta_grid) + center_y
return x_grid,y_grid,z_grid
depth=7
depth_from=3
fig = plt.figure(figsize=(5,10))
ax = fig.add_subplot(111, projection='3d')
Xc,Yc,Zc = data_for_cylinder_along_z(0,0,0.02,depth,depth_from)
ax.plot_surface(Xc, Yc, Zc, alpha=0.5, color='gray')
plt.show()
我想你可以使用 set_box_aspect
。这是示例:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
def data_for_cylinder_along_z(center_x,center_y,radius,Dto,Dfrom):
z = np.linspace(Dfrom, Dto, 50)
theta = np.linspace(0, 2*np.pi, 50)
theta_grid, z_grid=np.meshgrid(theta, z)
x_grid = radius*np.cos(theta_grid) + center_x
y_grid = radius*np.sin(theta_grid) + center_y
return x_grid,y_grid,z_grid
depth=7
depth_from=3
fig = plt.figure(figsize=(5,10))
ax = fig.add_subplot(111, projection='3d')
Xc,Yc,Zc = data_for_cylinder_along_z(0,0,0.02,depth,depth_from)
ax.set_box_aspect([1,1,5]) # set aspect ratio
ax.plot_surface(Xc, Yc, Zc, alpha=0.5, color='gray')
plt.show()
我正在绘制一个 3D 圆柱体 space 并且想夸大 z 轴以拉伸图像。
这是我使用的代码的简化版本和相应的图像。我已经将图形大小更改为我需要的大小,如何拉伸实际绘制的图像以便夸大 z 轴?
def data_for_cylinder_along_z(center_x,center_y,radius,Dto,Dfrom):
z = np.linspace(Dfrom, Dto, 50)
theta = np.linspace(0, 2*np.pi, 50)
theta_grid, z_grid=np.meshgrid(theta, z)
x_grid = radius*np.cos(theta_grid) + center_x
y_grid = radius*np.sin(theta_grid) + center_y
return x_grid,y_grid,z_grid
depth=7
depth_from=3
fig = plt.figure(figsize=(5,10))
ax = fig.add_subplot(111, projection='3d')
Xc,Yc,Zc = data_for_cylinder_along_z(0,0,0.02,depth,depth_from)
ax.plot_surface(Xc, Yc, Zc, alpha=0.5, color='gray')
plt.show()
我想你可以使用 set_box_aspect
。这是示例:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
def data_for_cylinder_along_z(center_x,center_y,radius,Dto,Dfrom):
z = np.linspace(Dfrom, Dto, 50)
theta = np.linspace(0, 2*np.pi, 50)
theta_grid, z_grid=np.meshgrid(theta, z)
x_grid = radius*np.cos(theta_grid) + center_x
y_grid = radius*np.sin(theta_grid) + center_y
return x_grid,y_grid,z_grid
depth=7
depth_from=3
fig = plt.figure(figsize=(5,10))
ax = fig.add_subplot(111, projection='3d')
Xc,Yc,Zc = data_for_cylinder_along_z(0,0,0.02,depth,depth_from)
ax.set_box_aspect([1,1,5]) # set aspect ratio
ax.plot_surface(Xc, Yc, Zc, alpha=0.5, color='gray')
plt.show()