python - 使用 Pandas/matplotlib 绘制日均值时更改日期时间刻度的格式

标签 python matplotlib plot pandas

<分区>

我计算日均值和标准差作为条形图。我的数据框如下所示:

                Ozone
2014-06-10  41.958586
2014-06-11  32.747222
2014-06-12  35.781250
2014-06-13  28.623264
2014-06-14  31.160764
2014-06-15  30.494444
2014-06-16  35.666667

[7 rows x 1 columns]

如您所见,索引行被很好地截断为每日日期。然而,当我尝试在条形图中绘制它时,七个条形中的每一个都有完整的日期,下面是“00:00:00”。这可能是 matplotlib 试图变得聪明,但我不知道如何格式化索引,以便只显示每日日期。

看起来像这样:

2014-06-13 00:00:00

你对如何改变这个有什么建议吗?

最佳答案

一种可能性是,由于 Pandas/Matplotlib 将日期作为 datetime 值,如果您将它们转换为字符串,那么您可以使用 datetime.strftime 控制格式方法。

关于python - 使用 Pandas/matplotlib 绘制日均值时更改日期时间刻度的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24259988/

相关文章:

python - 如何获取与 SQLAlchemy InstrumentedAttribute 对应的属性值?

python - tensorflow resize_image_with_crop_or_pad

python - 使用离散变量的二维离散彩色图

python - ggplot 在一个对象中绘制多个图

python 和 matplotlib 中的更新图

python - Python 中的 Shell 样式列表生成或变量表达式?

Python 正则表达式 : Matching bracket/parenthesis pairs

python - Jupyter 显示没有 plt.show() 的情节

python - 在 Python 中使用上面的箱线图绘制直方图

python - matplotlib - 图对象没有属性 'plot' 。引用问题