老实说,最简单的方法就是对TimeFormatter的_formats字典进行猴子补丁操作:
from enthought.chaco.scales.formatters import TimeFormatter
TimeFormatter._formats['days'] = ('%d/%m', '%d%a',)
如果你不想这么做,那么你需要子类化TimeFormatter。这很容易。更加繁琐的是让chaco.scales包创建的所有现有刻度系统都使用你的新子类而不是内置的TimeFormatter。如果你查看scales.time_scale.TimeScale,它在构造函数中接受一个“formatter”关键字参数。因此,在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)
抱歉,这个问题已经延迟了一个月。我并不经常查看StackOverflow。如果您有其他关于Chaco的问题,我建议您在Chaco用户邮件列表上注册...