python-3.x - 如何在 python3 中绘制简单的 3d 轴?
解决方案
这可能是一个很好的开端。尝试使用它。
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
fig = plt.figure(figsize=[8,8])
ax = fig.gca(projection = '3d')
# some settings
vleng = 4
aleng = vleng/3.
p = np.array([vleng, 0, 0])
q = np.array([0, vleng, 0])
r = np.array([0, 0, vleng])
ax.plot(*np.vstack([[0,0,0], p]).T, color='b')
ax.plot(*np.vstack([[0,0,0], q]).T, color='g')
ax.plot(*np.vstack([[0,0,0], r]).T, color='r')
# plotting arrow at terminal of the lines
ax.quiver(vleng, 0, 0, aleng, 0, 0, \
length=0.5, arrow_length_ratio=0.5, color='r')
ax.quiver(0, vleng, 0, 0, aleng, 0, \
length=0.5, arrow_length_ratio=0.5, color='m')
ax.quiver(0, 0, vleng, 0, 0, aleng, \
length=0.5, arrow_length_ratio=0.5, color='k')
ax.text3D(vleng+1.5, 0, 0, 'X')
ax.text3D(0, vleng+1.0, 0, 'y')
ax.text3D(0, 0, vleng+1.0, 'z')
ax.azim = 35 # y rotation (default=270)
ax.elev = 20 # x rotation (default=0)
ax.dist = 15 # zoom (define perspective)
ax.set_axis_off( ) # hide all grid
ax.set_aspect('equal')
# plot poly1
ax.plot3D( [3.5, 0.25, 2, 3.5], [1, 0.25, 2.5, 1], [1.9, 3.2, 3.8, 1.9], label = 'one line', color='pink' )
# projection of poly1 on xy-plane
ax.plot3D( [3.5, 0.25, 2, 3.5], [1, 0.25, 2.5, 1], [0, 0, 0, 0], label = 'one line', color='gray' )
#ax.legend()
plt.show()
推荐阅读
- python - Python递归二叉搜索树
- python - 安装依赖项时是否可以指定conda通道地址
- python - 如何根据 Pandas 中的行和列值突出显示单元格?
- linux - 如何从第n行到最后一行读取文本文件中的数据
- javascript - Javascript 在满足条件时更新数组,否则将新记录添加到数组中
- css - 将 Prismjs 用于语法突出显示的代码块正在破坏移动设备上的布局 -
元素不会采用动态宽度
- python-3.x - 利用 mypy 注释变量和返回值
- javascript - 我试图使用 javascript 制作待办事项列表,但无法附加所选选项
- php - 我需要帮助使不和谐卷曲
- java - 如何让我的多线程服务器/客户端聊天程序使用套接字向所有客户端回显消息?