2010-01-31 5 views
5

Enthought의 Chaco에서 TimeFormatter 클래스는 tick 레이블의 시간 문자열을 형식화하는 데 사용됩니다. 시간 형식 (time.strftime()과 같은 것)을 지정하는 방법이 있습니까?파이썬 chaco 축 레이블 시간 서식

월 및 일을 미국식 (MMDD)으로 표시 할 때 소스 코드가 형식을 하드 코드합니다. 시간/날짜 형식 힌트가 어떻게 든 (소스 코드 자체 (TimeFormatter._formats 사전)을 변경 이외의)이 작업을 수행 할 수있는 좋은 방법을 알고 해달라고 TimeFormatter

에 전달 될 수 있도록 좀 유연성을 추가

싶습니다

답변

4

솔직히, 가장 쉬운 방법은 TimeFormatter의 _formats 사전을 monkeypatch하는 것입니다 :이 작업을 수행하지 않으려면

from enthought.chaco.scales.formatters import TimeFormatter 
TimeFormatter._formats['days'] = ('%d/%m', '%d%a',) 

는, 당신은 TimeFormatter를 서브 클래스해야합니다. 쉽습니다. chaco.scales 패키지가 생성하는 기존의 모든 스케일 시스템을 내장 TimeFormatter가 아닌 새 서브 클래스로 사용하는 것이 더 귀찮은 일입니다. scales.time_scale.TimeScale을 보면 생성자에서 'formatter'키워드 인수를 사용할 수 있습니다. MDYScales 목록이 작성 될 때, time_scale.py의 하단에, 당신은 만들어야 할 것입니다 자신의 : 당신이 ScalesTickGenerator를 만들 때

다음
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())] 

, 당신은 이러한 저울에 전달해야 ScaleSystem :

euro_scale_system = CalendarScaleSystem(*(HMSScales + EuroMDYScales)) 
tick_gen = ScalesTickGenerator(scale=euro_scale_system) 

그런 다음 당신이이 틱 발전기를 제공 축을 만들 수 있습니다

axis = PlotAxis(tick_generator = tick_gen) 

HTH를 유감이 한 달 정도 지연이다. StackOverflow를 확인하지 않습니다. 다른 chaco 질문이있는 경우 chaco-users 메일 링리스트에 등록하는 것이 좋습니다 ...

+0

TimeFormatter._format 솔루션을 사용하는 경우 다른 chaco import 문을 사용하기 전에 설정해야합니다. 효과가 없다. –