如何使Python绘图具有交互性

问题描述 投票:0回答:1

我正在尝试制作一个以 3D 交互方式完成的绘图,以便我可以移动它以便从其他角度查看它。

cut_k = 0.35
height = 3

#slice at k = 0.08

#Create data for the cylinder
theta = np.linspace(0, 2 * np.pi, 1000)
z_cylinder = np.linspace(0, height, 1000)
theta, z_cylinder = np.meshgrid(theta, z_cylinder)
x_cylinder = cut_k* np.cos(theta)
y_cylinder = cut_k* np.sin(theta)

#plot surface
fig = plt.figure(figsize=(7, 7))
axes = fig.add_subplot(111, projection='3d')
axes.plot_surface(x_cylinder, y_cylinder, z_cylinder, color='red', alpha=1)

这是我的代码。

python visualization
1个回答
0
投票

我通常使用

%matplotlib widget
将 Matplotlib 绘图更改为交互式。但是,如果您想绘制二维图形,您可能需要运行
%matplotlib inline
这会重置它。可能不是最有效的方法,但它总是对我有用。我希望这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.