【问题标题】:Pandas xaxis auto-format issuePandas xaxis 自动格式化问题
【发布时间】:2012-07-22 01:54:02
【问题描述】:
from pandas import *
import datetime
DataFrame([1,1], index =  [ datetime.datetime(2012,1,1), datetime.datetime(2012,9,1) ] ).plot()

给出一个 xaxis 不可读的图。我认为原因是tools\plotting.py 中的condition(决定自动调整)是错误的。

condition = (not self._use_dynamic_x
             and df.index.is_all_dates
             and not self.subplots
             or (self.subplots and self.sharex))

第一行不应该是self._use_dynamic_x()吗?

【问题讨论】:

    标签: python matplotlib pandas


    【解决方案1】:

    我认为这是pandas的一个bug,应该是self._use_dynamic_x(),请发issue给pandas,绕过这个问题:

    import pylab as pl
    from pandas import *
    import datetime
    df = DataFrame([1,1], index =  [ datetime.datetime(2012,1,1), datetime.datetime(2012,9,1) ] )
    df.plot()
    pl.xticks(rotation=90)
    

    【讨论】:

    【解决方案2】:

    你用的是什么版本的熊猫?

    我刚刚试了一下,轴看起来不错:

    http://imgur.com/FpoR7

    我在 pandas 0.8.1 和 matplotlib 1.1.0

    【讨论】:

    • 您的 xaxis 看起来比我的稍好 - 请参阅 image,但它不像 condition 为 True 时那样倾斜。我正在使用 1.1.1rc2 和 0.8.0。刚刚升级到 0.8.1,但看不出有什么不同。
    • 啊,我明白了……除了没有旋转,你觉得标签还有什么问题吗?
    • 不,问题只是在熊猫身上,而不是在情节本身。
    • 感谢 github 问题。如果您想尝试,我只是对 master 进行了修复。
    • 谢谢@Chang She。不确定这是否是正确的论坛,但我想贡献 - 我需要什么才能说只为那一行代码创建拉取请求? IE。对我来说 cvs 签出代码、在 iPython 中测试我的更改而不是使用 prod 版本然后创建拉取请求有多容易?在某处有教程吗?我熟悉 subversion,并且在专有系统中完成了数千次 cvs 提交,只是不熟悉开源工具。
    猜你喜欢
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 2018-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多