[英]How do I plot data with time?
I have a csv
where I have recorded my calorie intake throughout the day for 7 days.我有一个
csv
,我在其中记录了 7 天全天的卡路里摄入量。
There are two columns in the csv: time of day and amount of calories csv 中有两列:一天中的时间和卡路里量
I need to load this data and plot it in a graph.我需要将这些数据和 plot 加载到图表中。 I'm trying to do a line plot where I compare the 7 days to each other on the same graph.
我正在尝试做一条线 plot 我在同一张图上比较 7 天。
The x ticks range from 0-24 (representing each hour of the day), but I don't know how to plot each recording accordingly to the x ticks. x 刻度的范围是 0-24(代表一天中的每个小时),但我不知道如何根据 x 刻度来 plot 每个记录。 I'm not sure I'm making sense.
我不确定我是否有道理。 What I mean is that if I have a recording at 21:30, it should plot between the x ticks, 21 and 22, but I'm not sure how to do that.
我的意思是,如果我在 21:30 有录音,它应该在 x 刻度 21 和 22 之间为 plot,但我不知道该怎么做。
Any help is appreciated.任何帮助表示赞赏。
not really sure what you expected from x-axis to be.不太确定您对 x 轴的期望是什么。 Let's take the following example:
让我们看下面的例子:
import pandas
from matplotlib import pyplot as plt
df = pandas.DataFrame({"Time":["07:10", "09:30", "21:30"], "Value": [1000, 1200, 1400]})
plt.plot(df["Time"], df["Value"] ,'ro')
plt.show()
output: output:
As you can see, it will automatically will plot the x-values (time of day).如您所见,它将自动将 X 值(一天中的时间) plot。 If you want to be precisely 0-24 with 1 hour jump, I recommend to first convert values to
datetime
or time
objects and work with them, as it easier that way.如果您想在 1 小时内精确到 0-24,我建议您首先将值转换为
datetime
时间或time
对象并使用它们,因为这样更容易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.