![](/img/trans.png)
[英]How can I plot the animation from the csv data with date time information?
[英]How can I plot data based on and ordered by date and time in python?
我有兩個列表,一個包含日期時間元素,另一個包含數值。 我想 plot 散點圖 plot ,其中 X 軸是日期,Y 軸是數值。 日期時間的格式如下:“YYYY-MM-DD HH:mm:ss”。
datetimes = ['2015-01-10 10:00:00', '2015-01-11 10:00:00', '2015-01-10 11:00:00', '2015-01-10 10:30:00']
numerical_values = [3.0, 2.0, 10.0, 4.0]
我怎樣才能 plot 按日期時間排序的散點圖?
您可以對列表進行排序並跟蹤您的坐標:
datetimes = ['2015-01-10 10:00:00', '2015-01-11 10:00:00', '2015-01-10 11:00:00', '2015-01-10 10:30:00']
numerical_values = [3.0, 2.0, 10.0, 4.0]
x_y = sorted([(x,y) for (x,y) in zip(datetimes,numerical_values)], key=lambda z: z[0])
x = []
y = []
for X, Y in x_y:
x.append(X)
y.append(Y)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.