【问题标题】:Use DataFrame index as x-axis ticks使用 DataFrame 索引作为 x 轴刻度
【发布时间】:2017-08-18 09:25:23
【问题描述】:

我有一个带有索引(时间)和一列(速率)的 DataFrame。我只想使用时间作为直方图中的 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)

print(data) 产生:

          Rate
Time          
0     1.191309
1     1.208280
2     1.244835
3     1.279342
4     1.307912
5     1.532720

【问题讨论】:

  • 试试这个:data.plot.hist()
  • 这似乎没有任何改变
  • 您想绘制什么精确度以及您当前的问题/问题是什么?
  • 我只需要一个直方图,其中 y 轴是“速率”,x 轴是“时间”。目前我所拥有的就是给我这个puu.sh/uXT1s/579adee755.png 感谢您的帮助,Max。
  • 你确定你没有混淆hist 情节和bar 情节吗?您需要条形图:data.plot.bar()

标签: python pandas


【解决方案1】:

演示:

import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot')

来源 DF:

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

Bar-plot:

In [126]: data.plot.bar(rot=0)
Out[126]: <matplotlib.axes._subplots.AxesSubplot at 0xe1fe048>

Histogram plot:

In [131]: data.plot.hist(rot=0)
Out[131]: <matplotlib.axes._subplots.AxesSubplot at 0xe7611d0>

【讨论】:

    猜你喜欢
    • 2021-03-05
    • 2020-01-09
    • 2012-07-20
    • 2015-02-13
    • 2018-06-17
    • 2012-12-12
    • 2012-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多