python 如何绘制不同形状的数组?

jv4diomz  于 2023-02-21  发布在  Python
关注(0)|答案(1)|浏览(121)

我有三个不同的csv文件,每个文件有两列。第一列是纪元,第二列是强度。对于前两个文件,长度是相同的- 60。但第三个文件,的长度为1030。我想在同一个图上绘制所有这些csv文件。我已经尝试过了。文件1和文件2的历元列的时间戳间隔为1。5分钟,但对于文件3,时间戳是随机的。我曾考虑为时间戳创建偏移,但我不确定这将如何工作。
由于文件很大,我包括了数据的片段。

epoch_1 = np.array(['2020-07-11T02:00:30.000Z', '2020-07-11T02:01:30.000Z','2020-07-11T02:02:30.000Z', '2020-07-11T02:03:30.000Z','2020-07-11T02:04:30.000Z', '2020-07-11T02:05:30.000Z','2020-07-11T02:06:30.000Z', '2020-07-11T02:07:30.000Z','2020-07-11T02:08:30.000Z', '2020-07-11T02:09:30.000Z','2020-07-11T02:10:30.000Z', '2020-07-11T02:11:30.000Z','2020-07-11T02:12:30.000Z', '2020-07-11T02:13:30.000Z','2020-07-11T02:14:30.000Z', '2020-07-11T02:15:30.000Z','2020-07-11T02:16:30.000Z', '2020-07-11T02:17:30.000Z','2020-07-11T02:18:30.000Z', '2020-07-11T02:19:30.000Z'])

intensity_1 = np.array([1.03587, 1.03187, 1.03561, 1.02893, 1.04659, 1.03633, 1.0481,1.04156, 1.02164, 1.02741, 1.02675, 1.03651, 1.03713, 1.0252,1.02853, 1.0378 , 1.04374, 1.01427, 1.0387 , 1.03389])

epoch_2 = np.array(['2020-07-11T02:00:30.000Z', '2020-07-11T02:01:30.000Z','2020-07-11T02:02:30.000Z', '2020-07-11T02:03:30.000Z','2020-07-11T02:04:30.000Z', '2020-07-11T02:05:30.000Z','2020-07-11T02:06:30.000Z', '2020-07-11T02:07:30.000Z','2020-07-11T02:08:30.000Z', '2020-07-11T02:09:30.000Z','2020-07-11T02:10:30.000Z', '2020-07-11T02:11:30.000Z','2020-07-11T02:12:30.000Z', '2020-07-11T02:13:30.000Z','2020-07-11T02:14:30.000Z', '2020-07-11T02:15:30.000Z','2020-07-11T02:16:30.000Z', '2020-07-11T02:17:30.000Z','2020-07-11T02:18:30.000Z', '2020-07-11T02:19:30.000Z'])

intensity_2 = np.array([1.02097 , 1.06292 , 1.08389 , 0.958054, 1.10487, 1.08389,1.02097 , 1.04195 , 0.979027, 1.08389 , 1.04195 , 1.04195, 1.04195 , 0.937081, 1.25168 , 1.06292 , 1.04195 , 1.04195 ,1.08389,1.08389])

epoch_3 = np.array(['2020-07-11T02:00:02.676555136Z', '2020-07-11T02:00:06.171916544Z','2020-07-11T02:00:09.667033856Z', '2020-07-11T02:00:13.162395264Z','2020-07-11T02:00:16.657756672Z', '2020-07-11T02:00:20.152873856Z','2020-07-11T02:00:23.648235392Z', '2020-07-11T02:00:27.143352576Z','2020-07-11T02:00:30.638713984Z', '2020-07-11T02:00:34.134075392Z','2020-07-11T02:00:37.629192576Z', '2020-07-11T02:00:41.124554112Z','2020-07-11T02:00:44.619915520Z', '2020-07-11T02:00:48.115032704Z','2020-07-11T02:00:51.610394112Z', '2020-07-11T02:00:55.105511424Z','2020-07-11T02:00:58.600872832Z', '2020-07-11T02:01:02.096234240Z','2020-07-11T02:01:05.591351552Z', '2020-07-11T02:01:09.086712832Z',])

intensity_3 = np.array([4.08873e-20, 4.32314e-20, 4.89188e-20, 4.94567e-20, 3.44891e-20,4.07720e-20, 3.95423e-20, 5.02253e-20, 4.24629e-20, 3.67563e-20,4.22323e-20, 3.39319e-20, 4.10026e-20, 4.07720e-20, 4.57677e-20,4.40384e-20, 3.34515e-20, 4.10026e-20, 4.38847e-20, 4.36157e-20])

最后一个数组需要转换为日志,使用--

intensity_3 = np.log(intensity_3/1e-21)/np.max(np.log(intensity_3/1e-21))

当我用下面的公式来绘制它的时候--

plt.plot(epoch_1, intensity_1)
plt.plot(epoch_2, intensity_2)
plt.plot(epoch_3, intensity_3)
plt.yscale('log')

它看起来像是--

有没有办法为日期创建偏移量?我希望intensity_3数据与其他两个数据位于相同的范围内。

iswrvxsc

iswrvxsc1#

如果您想在相同大小的x轴上显示测量结果,则必须对测量结果进行后处理和归一化:
一个基本的方法是将x轴重新缩放到相同的大小。在下面的例子中,我将x轴重新缩放到100的大小,并且这些范围之间的点数根据纪元中的值的数量(len(epoch_1))进行调整。
这将重新调整所有的时间点,独立于它们的测量量,到相同大小的x轴上。

xaxe1= np.linspace(0,100,len(epoch_1))
xaxe2= np.linspace(0,100,len(epoch_2))
xaxe3= np.linspace(0,100,len(epoch_3))

#epoch_3=epoch_3-(epoch_3-epoch_2)

plt.plot(xaxe1, intensity_1)
plt.plot(xaxe2, intensity_2)
plt.plot(xaxe3, intensity_3)
plt.yscale('log')
plt.show()

相关问题