如何使用Matplotlib制作简单的3D线? [英] How can I make a simple 3D line with Matplotlib?

查看:87
本文介绍了如何使用Matplotlib制作简单的3D线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想生成线条,这些线条是我从3D数组中获得的.

I want to generate the lines, which I get from an array in 3D.

这是代码:

VecStart_x = [0,1,3,5]
VecStart_y = [2,2,5,5]
VecStart_z = [0,1,1,5]
VecEnd_x = [1,2,-1,6]
VecEnd_y = [3,1,-2,7]
VecEnd_z  =[1,0,4,9]

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

ax.plot([VecStart_x ,VecEnd_x],[VecStart_y,VecEnd_y],[VecStart_z,VecEnd_z])
plt.show()
Axes3D.plot()

我收到那个错误:

ValueError:第三个参数必须是格式字符串

ValueError: third arg must be a format string

推荐答案

我猜,你想绘制 4 行.然后,您可以尝试

I guess, you want to plot 4 lines. Then you can try

for i in range(4):
    ax.plot([VecStart_x[i], VecEnd_x[i]], [VecStart_y[i],VecEnd_y[i]],zs=[VecStart_z[i],VecEnd_z[i]])

正如@Nicolas所建议的,请看看matplotlib画廊.

As @Nicolas have suggested, do have a look at the matplotlib gallery.

这篇关于如何使用Matplotlib制作简单的3D线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆