题
在Enthought的查科,所述TimeFormatter
类用于格式化蜱的时间字符串
标签。有没有指定的时间格式(像time.strftime()
)的方式。
现在的源代码硬编码显示月和月中的日时的美国式(MMDD)的格式。我想添加一些灵活性,使得时间/日期格式的提示会以某种方式被传递到TimeFormatter
我不知道的任何好的方式做到这一点(除改变源代码本身(TimeFormatter._formats
字典))
解决方案
真的,最简单的方法将是对猴补丁的TimeFormatter的_formats词典:
from enthought.chaco.scales.formatters import TimeFormatter
TimeFormatter._formats['days'] = ('%d/%m', '%d%a',)
如果你不想这样做,那么你需要继承TimeFormatter。这很容易。更重要的是笨重的是使所有的现有规模系统的chaco.scales包创建使用新的子类,而不是内置TimeFormatter。如果你看一下scales.time_scale.TimeScale,它接受在构造一个“格式化”关键字参数。因此,在time_scale.py的底部,MDYScales列表生成时,你就必须创建自己的:
EuroMDYScales = [TimeScale(day_of_month=range(1,31,3), formatter=MyFormatter()),
TimeScale(day_of_month=(1,8,15,22), formatter=MyFormatter()),
TimeScale(day_of_month=(1,15), formatter=MyFormatter()),
TimeScale(month_of_year=range(1,13), formatter=MyFormatter()),
TimeScale(month_of_year=range(1,13,3), formatter=MyFormatter()),
TimeScale(month_of_year=(1,7), formatter=MyFormatter()),
TimeScale(month_of_year=(1,), formatter=MyFormatter())]
然后,当创建ScalesTickGenerator,需要在这些尺度到ScaleSystem传递:
euro_scale_system = CalendarScaleSystem(*(HMSScales + EuroMDYScales))
tick_gen = ScalesTickGenerator(scale=euro_scale_system)
然后可以创建轴线,赋予它这蜱发生器:
axis = PlotAxis(tick_generator = tick_gen)
HTH,遗憾,这是约一个月的滞后。我真的不检查StackOverflow的非常多。如果您还有其他问题查科,我建议你在查科用户邮件列表注册...
不隶属于 StackOverflow