具有毫秒x轴的图显示负时间值

时间:2017-06-10 05:17:03

标签: python pandas matplotlib

我有一个包含时间和价值的数据框。

>>> df.dtypes
Time          timedelta64[ns]
Value                 float64
dtype: object

                 Time  Value
0     09:42:29.752840  47.99
1     09:42:29.955840  47.99
2     09:42:31.150360  47.99
3     09:42:35.151380  47.99
4     09:42:35.954910  47.99
5     09:42:43.554140  47.99
6     09:42:45.358660  47.99
7     09:42:46.746380  47.99
8     09:42:47.355820  47.99
9     09:42:47.747740  47.99
10    09:42:48.945820  47.98
11    09:42:48.945820  47.98
12    09:42:50.555370  47.98
.....

正如您所看到的,时间列仅由小时:分钟:秒。毫秒timedelta64类型值组成,也许这就是为什么我无法通过命令 plt正确绘制它的原因。 plot(df.Time,df.Value)

enter image description here

我的问题是,如何绘制它的时间序列图,以及是否可以以1秒为单位添加另一个x轴。

import sys
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.read_csv("c:/3h.csv")

df = df[['Time', 'Value']]

df.Time = pd.to_timedelta(df.Time.str.replace(r'\:(\d+)$', r'.\1'), errors='coerce')

plt.plot(df['Time'], df['Value'])

plt.show()

>>> df
             Time  Value
0      09:42:29:75284  47.99
1      09:42:29:95584  47.99
2      09:42:31:15036  47.99
3      09:42:35:15138  47.99
4      09:42:35:95491  47.99
5      09:42:43:55414  47.99
6      09:42:45:35866  47.99
7      09:42:46:74638  47.99
9      09:42:47:74774  47.99
10     09:42:48:94582  47.98
11     09:42:48:94582  47.98
12     09:42:50:55537  47.98
13     09:42:52:75210  47.98
14     09:42:53:74199  47.98
15     09:42:53:96098  47.98
16     09:42:54:75283  47.99
17     09:42:54:75283  47.99
18     09:42:54:75283  47.99
19     09:42:54:95602  47.99
20     09:42:55:75305  47.99
21     09:42:59:36113  47.98
22     09:42:59:54864  47.98
23     09:43:00:54874  47.98
24     09:43:00:95504  47.99
25     09:43:00:95504  47.99
26     09:43:00:95504  47.99
27     09:43:00:95504  47.99
28     09:43:00:95504  47.99
29     09:43:00:95504  47.99
...               ...    ...
18894  01:07:44:47178  48.15
18895  01:07:44:47178  48.15
18896  01:07:44:47178  48.15
18897  01:07:44:48733  48.15
18898  01:07:44:48733  48.15
18899  01:07:44:48733  48.15
18900  01:07:44:48733  48.15
18901  01:07:44:48733  48.15
18902  01:07:44:48733  48.15
18903  01:07:44:48733  48.15
18904  01:07:44:50296  48.15
18905  01:07:44:50296  48.15
18906  01:07:44:50296  48.15
18907  01:07:44:50296  48.15
18908  01:07:44:50296  48.15
18909  01:07:44:50296  48.15
18910  01:07:44:65922  48.15
18911  01:07:44:65922  48.15
18912  01:07:44:86237  48.15
18913  01:07:45:65955  48.15
18914  01:07:45:65955  48.15
18915  01:07:45:86248  48.15
18916  01:07:45:86248  48.15
18917  01:07:47:87209  48.15
18918  01:07:48:05943  48.15
18919  01:07:48:46590  48.15
18920  01:07:48:46590  48.15
18921  01:07:48:66883  48.15
18922  01:07:48:87202  48.15
18923  01:07:49:05972  48.15

0 个答案:

没有答案