用numpy和scipy绘制图形

2024-06-06 23:50:50 发布

您现在位置:Python中文网/ 问答频道 /正文

在时间t1有x1,y1,z1坐标,在时间t2有x2,y2,z2坐标。我想为他们画出图表。

我有所有的核弹阵列。

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数组?


Tags: numpy图表时间绘制用图表数组t1x1
2条回答

根据你的评论:

I have created 3 plots for every coordinates for A and B. I want to show x, y and z coordinates in one graph only for A and B. how can I show that?

我相信你要找的是:

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的字符串

如果要显示A,B的三维位移,请使用模块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

相关问题 更多 >