我试图用matplotlib绘制一个3d Cartesian coordinate system,原点居中,3个方向带箭头,类似这样的东西
的数据
我已经用这个代码绘制了一个2d版本,基于这个post
def build_cartesian_plane(max_quadrant_range):
""" The quadrant range controls the range of the quadrants"""
l = []
zeros = []
f, ax = plt.subplots(figsize=(5,5))
plt.grid(True, color='grey', zorder=0,alpha=.5)
head_width = float(0.05) * max_quadrant_range
head_length = float(0.1) * max_quadrant_range
ax.arrow(0, 0, max_quadrant_range, 0, head_width=head_width, head_length=head_length, fc='k', ec='k',zorder=100)
ax.arrow(0, 0, 0, max_quadrant_range, head_width=head_width, head_length=head_length, fc='k', ec='k', zorder=100)
counter_dash_width = max_quadrant_range * 0.02
dividers = [0,.1,.2,.3,.4, .5, .6, .7, .8, .9, 1]
ax.spines['top'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
for i in dividers:
ax.plot([-counter_dash_width, counter_dash_width], [i*max_quadrant_range, i*max_quadrant_range], color='k')
ax.plot([i * max_quadrant_range, i*max_quadrant_range], [-counter_dash_width, counter_dash_width], color='k')
ax.plot([-counter_dash_width, counter_dash_width], [-i * max_quadrant_range, -i * max_quadrant_range], color='k')
ax.plot([-i * max_quadrant_range, -i * max_quadrant_range], [-counter_dash_width, counter_dash_width], color='k')
l.append(i * max_quadrant_range)
l.append(-i * max_quadrant_range)
zeros.append(0)
zeros.append(0)
build_cartesian_plane(10)
plt.show()
字符串
的
似乎ax.arrow
不支持3d来做这件事,所以,我不得不使用xplot来绘制一个简单的3d版本。
ax.quiver(0, 0, 0, 0, 3, 0,
arrow_length_ratio=0.1)
ax.quiver(0, 0, 0, 3, 0, 0,
arrow_length_ratio=0.1)
ax.quiver(0, 0, 0, 0, 0, 3,
arrow_length_ratio=0.1)
limt = 2
ax.set_xlim([-limt, limt])
ax.set_ylim([-limt, limt])
ax.set_zlim([-limt, limt])
型
并得到了这个
的
我不熟悉martini,所以我不确定用matplotlib绘制3d笛卡尔坐标系是否可行。
任何提示将不胜感激。
2条答案
按热度按时间i5desfxk1#
我发现了两个有用的链接,并把它们放在一起。也许这就是你要找的:对于箭头:Drawing a righthand coordinate system in mplot3d和3D立方体:python : plotting a wireframe 3D cuboid先看看输出:x1c 0d1x
字符串
希望这对你有帮助。我还需要漂亮的箭头,所以如果你发现更好的东西,请发邮件;)
sycxhyv72#
有关实现了
do_3d_projection
的更新版本,请查看:https://gist.github.com/WetHat/1d6cd0f7309535311a539b42cccca89c