Python 使用数据帧索引作为x轴刻度
我有一个带有索引(时间)和一列(速率)的数据帧。我只想用时间作为直方图中的x刻度,用速率作为y轴 以下是我到目前为止得到的信息:Python 使用数据帧索引作为x轴刻度,python,pandas,Python,Pandas,我有一个带有索引(时间)和一列(速率)的数据帧。我只想用时间作为直方图中的x刻度,用速率作为y轴 以下是我到目前为止得到的信息: data = pd.DataFrame.from_dict(rates,orient='index') data.index.name = 'Time' data.columns = ['Rate'] data.plot(kind='hist', x = data.index.values) 打印(数据)产生: Rate Time
data = pd.DataFrame.from_dict(rates,orient='index')
data.index.name = 'Time'
data.columns = ['Rate']
data.plot(kind='hist', x = data.index.values)
打印(数据)
产生:
Rate
Time
0 1.191309
1 1.208280
2 1.244835
3 1.279342
4 1.307912
5 1.532720
演示:
资料来源:
In [122]: data
Out[122]:
Rate
Time
0 1.191309
1 1.208280
2 1.244835
3 1.279342
4 1.307912
5 1.532720
:
[126]中的:data.plot.bar(rot=0)
出[126]:
:
[131]中的:data.plot.hist(rot=0)
出[131]:
尝试以下操作:
data.plot.hist()
这似乎没有改变任何东西您想要绘制什么样的示例以及当前的问题/问题?我只需要一个直方图,其中y轴是“速率”,x轴是“时间”。此时此刻,我所拥有的正是给我这个感谢的帮助,Max。你确定你没有混淆hist
绘图和bar
绘图吗?是否需要条形图:data.plot.bar()
?
In [122]: data
Out[122]:
Rate
Time
0 1.191309
1 1.208280
2 1.244835
3 1.279342
4 1.307912
5 1.532720
In [126]: data.plot.bar(rot=0)
Out[126]: <matplotlib.axes._subplots.AxesSubplot at 0xe1fe048>
In [131]: data.plot.hist(rot=0)
Out[131]: <matplotlib.axes._subplots.AxesSubplot at 0xe7611d0>