在numpy,scipy中绘制图形

时间:2014-01-16 05:14:51

标签: python numpy scipy mplot3d

我在时间t1协调x1,y1,z1,并且在时间t2我有x2,y2,z2坐标。我想为他们绘制图表。

我有所有numpy数组。

A = [[44.254  44.114  44.353  44.899  45.082] [-0.934  0.506  1.389  0.938  0.881] [44.864  45.225  44.005  42.981  46.356]]

t1 = [0 1.4911475447  1.5248639284  1.2450273089    3.3804382852]

B = [[44.254  48.4877582254 43.0268091866   47.3166368948   47.7110371397] [-0.934  1.0837036817    4.8307913511    6.2772868228    9.6580229826] [44.864   47.1020391758   43.0633715949   42.1564814645   42.0223003717]]

t2 = [0 0.00392157  0.00784314  0.01176471  0.01568627 ]

如何在图表中绘制这些numpy数组?

2 个答案:

答案 0 :(得分:2)

如果要显示A,B的 3d位移,请使用模块mpl_toolkits.mplot3d

A = [[44.254, 44.114, 44.353, 44.899, 45.082],[-0.934, 0.506, 1.389, 0.938, 0.881],[44.864, 45.225, 44.005, 42.981, 46.356]]
t1 = [0, 1.4911475447, 1.5248639284, 1.2450273089, 3.3804382852]
B = [[44.254, 48.4877582254, 43.0268091866,  47.3166368948,  47.7110371397], [-0.934, 1.0837036817, 4.8307913511, 6.2772868228, 9.6580229826],  [44.864,  47.1020391758,  43.0633715949,  42.1564814645,  42.0223003717]]
t2 = [0, 0.00392157, 0.00784314, 0.01176471, 0.01568627 ]

import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D
ax3d=plt.gca(projection='3d')
ax3d.plot(A[0], A[1], A[2], 'r',)
ax3d.scatter(A[0], A[1], A[2], c='r')

ax3d.plot(B[0], B[1], B[2], 'g',)
ax3d.scatter(B[0], B[1], B[2], c='g')

plt.show()

情节结果如下: enter image description here

如果您想添加注释以标记A,B的起点,请参阅question post

答案 1 :(得分:1)

根据您的评论:

  

我为A和B的每个坐标创建了3个图。我想在一个图中仅为A和B显示x,y和z坐标。我该如何显示?

我相信你要找的是:

A = [[44.254, 44.114, 44.353, 44.899, 45.082],[-0.934, 0.506, 1.389, 0.938, 0.881],[44.864, 45.225, 44.005, 42.981, 46.356]]
t1 = [0, 1.4911475447, 1.5248639284, 1.2450273089, 3.3804382852]
B = [[44.254, 48.4877582254, 43.0268091866,  47.3166368948,  47.7110371397], [-0.934, 1.0837036817, 4.8307913511, 6.2772868228, 9.6580229826],  [44.864,  47.1020391758,  43.0633715949,  42.1564814645,  42.0223003717]]
t2 = [0, 0.00392157, 0.00784314, 0.01176471, 0.01568627 ]

for i in range(len(A)):
    figure(1)
    plot(t1,A[i],'o')
    #figure(2)
    plot(t2,B[i],'o')
show()

请注意figure(x)将当前数字设置为x,或者如果它不存在则创建它。 plot函数的格式为plot(x,y,'marker_style'),其中'marker_style'是定义的字符串here