熊猫:如何在pd.DataFrame.plot()中在x轴上显示小网格线

 宫金丹865 发布于 2023-02-10 09:57

有没有办法在做pandas.DataFrame.plot()时控制网格格式?

具体来说,我想显示用于绘制具有日期时间索引的x轴的DataFrame的次要网格线.

这可以通过DataFrame.plot()吗?

df = pd.DataFrame.from_csv(csv_file, parse_dates=True, sep=' ')

Bastiaan.. 17

也许这个功能去年不存在,但在版本0.19.2中你可以这样做:

df.plot(grid=True)

见文档.

2 个回答
  • 这将以每周频率为S&p500绘制少量xticks和网格:

    import pandas.io.data as web
    ts = web.DataReader("^GSPC", "yahoo", start=dt.date( 2013, 6, 1 ))[ 'Adj Close' ]
    
    ax = ts.plot()
    xtick = pd.date_range( start=ts.index.min( ), end=ts.index.max( ), freq='W' )
    ax.set_xticks( xtick, minor=True )
    ax.grid('on', which='minor', axis='x' )
    ax.grid('off', which='major', axis='x' )
    

    在此输入图像描述

    2023-02-10 10:00 回答
  • 也许这个功能去年不存在,但在版本0.19.2中你可以这样做:

    df.plot(grid=True)
    

    见文档.

    2023-02-10 10:01 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有