python chaco轴标签时间格式
在Enthought的Chaco中,TimeFormatter
类用于格式化tick的时间字符串 标签。有没有办法指定时间格式(例如 time.strftime()
)。
源代码现在将显示月份和日期时的格式硬编码为美国风格 (MMDD)。我想添加一些灵活性,以便时间/日期格式提示以某种方式传递给 TimeFormatter
我不知道有什么好的方法可以做到这一点(除了更改源代码本身(>TimeFormatter._formats
字典))
In Enthought's Chaco, the TimeFormatter
class is used to format the time string of the tick
labels. is there a way to specify the time format (something like time.strftime()
).
the source code now hard-codes the format when displaying month and day of the month to the american style (MMDD). I would like to add some flexibility so that the time/date format hints would somehow be passed to the TimeFormatter
I dont know of any nice way to do this (other than changing the source code itself (TimeFormatter._formats
dictionary))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老实说,最简单的方法是对 TimeFormatter 的 _formats 字典进行猴子补丁:
如果您不想这样做,那么您需要子类化 TimeFormatter。这很容易。更麻烦的是让 chaco.scales 包创建的所有现有缩放系统使用新的子类而不是内置的 TimeFormatter。如果您查看scales.time_scale.TimeScale,它在构造函数中接受“formatter”关键字参数。因此,在 time_scale.py 的底部,当构建 MDYScales 列表时,您必须创建自己的:
然后,当您创建 ScalesTickGenerator 时,您需要将这些比例传递到 ScaleSystem:
然后您可以创建轴,给它这个刻度生成器:
HTH,抱歉,这大约有一个月的滞后。我不太常查看 StackOverflow。如果您还有其他 chaco 问题,我建议您在 chaco 用户邮件列表上注册......
Honestly, the easiest way is going to be to monkeypatch the TimeFormatter's _formats dictionary:
If you don't want to do this, then you need to subclass TimeFormatter. That's easy. What's more cumbersome is making all the existing scale systems that the chaco.scales package creates use your new subclass rather than the built-in TimeFormatter. If you look at scales.time_scale.TimeScale, it accepts a 'formatter' keyword argument in the constructor. So, at the bottom of time_scale.py, when the MDYScales list is built, you'd have to create your own:
Then, when you create the ScalesTickGenerator, you need to pass in these scales to the ScaleSystem:
Then you can create the axis, giving it this tick generator:
HTH, sorry this is about a month lag. I don't really check StackOverflow very much. If you have other chaco questions, I'd recommend signing up on the chaco-users mailing list...