Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 76ce690

Browse files
committed
created date ticker factory
svn path=/trunk/matplotlib/; revision=1750
1 parent c154f24 commit 76ce690

5 files changed

Lines changed: 50 additions & 42 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
New entries should be added at the top
22

3+
2005-09-14 Factored out auto date locator/formatter factory code into
4+
matplotlib.date.date_ticker_factory
5+
36
2005-09-13 Added Mark's axes positions history patch #1286915
47

58
2005-09-09 Added support for auto canvas resizing with

examples/interactive.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import code
2323
import threading
2424

25-
import pygtk
26-
pygtk.require("2.0")
2725
import gobject
2826
import gtk
2927

examples/interactive2.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
# See www.python.org/2.2/license.html for
66
# license details.
77
#
8-
import pygtk
9-
pygtk.require('2.0')
108
import gtk
119
import gtk.gdk
1210

lib/matplotlib/axes.py

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@
4646
import matplotlib
4747

4848
if matplotlib._havedate:
49-
from dates import YearLocator, MonthLocator, WeekdayLocator, \
50-
DayLocator, HourLocator, MinuteLocator, DateFormatter,\
51-
SEC_PER_MIN, SEC_PER_HOUR, SEC_PER_DAY, SEC_PER_WEEK
49+
from dates import date_ticker_factory
5250

5351

5452
def _process_plot_format(fmt):
@@ -2620,40 +2618,7 @@ def plot_date(self, d, y, fmt='bo', tz=None, **kwargs):
26202618

26212619
span = self.dataLim.intervalx().span()
26222620

2623-
if span==0: span = 1/24.
2624-
2625-
minutes = span*24*60
2626-
hours = span*24
2627-
days = span
2628-
weeks = span/7.
2629-
months = span/31. # approx
2630-
years = span/365.
2631-
2632-
numticks = 5
2633-
if years>numticks:
2634-
locator = YearLocator(int(years/numticks), tz=tz) # define
2635-
fmt = '%Y'
2636-
elif months>numticks:
2637-
locator = MonthLocator(tz=tz)
2638-
fmt = '%b %Y'
2639-
elif weeks>numticks:
2640-
locator = WeekdayLocator(tz=tz)
2641-
fmt = '%a, %b %d'
2642-
elif days>numticks:
2643-
locator = DayLocator(interval=int(math.ceil(days/numticks)), tz=tz)
2644-
fmt = '%b %d'
2645-
elif hours>numticks:
2646-
locator = HourLocator(interval=int(math.ceil(hours/numticks)), tz=tz)
2647-
fmt = '%H:%M\n%b %d'
2648-
elif minutes>numticks:
2649-
locator = MinuteLocator(interval=int(math.ceil(minutes/numticks)), tz=tz)
2650-
fmt = '%H:%M:%S'
2651-
else:
2652-
locator = MinuteLocator(tz=tz)
2653-
fmt = '%H:%M:%S'
2654-
2655-
2656-
formatter = DateFormatter(fmt, tz=tz)
2621+
locator, formatter = date_ticker_factory(span, tz)
26572622
self.xaxis.set_major_locator(locator)
26582623
self.xaxis.set_major_formatter(formatter)
26592624
self.autoscale_view()

lib/matplotlib/dates.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
DateIndexFormatter - date plots with implicit x indexing.
7676
7777
"""
78-
import sys, re, time
78+
import sys, re, time, math
7979
import locale
8080

8181
import matplotlib
@@ -703,6 +703,49 @@ def mx2num(mxdates):
703703
for t in dates: print formatter(t)
704704

705705

706+
def date_ticker_factory(span, tz=None, numticks=5):
707+
"""
708+
Create a date locator with numticks (approx) and a date formatter
709+
for span in days. Return value is (locator, formatter)
710+
711+
712+
"""
713+
714+
if span==0: span = 1/24.
715+
716+
minutes = span*24*60
717+
hours = span*24
718+
days = span
719+
weeks = span/7.
720+
months = span/31. # approx
721+
years = span/365.
722+
723+
if years>numticks:
724+
locator = YearLocator(int(years/numticks), tz=tz) # define
725+
fmt = '%Y'
726+
elif months>numticks:
727+
locator = MonthLocator(tz=tz)
728+
fmt = '%b %Y'
729+
elif weeks>numticks:
730+
locator = WeekdayLocator(tz=tz)
731+
fmt = '%a, %b %d'
732+
elif days>numticks:
733+
locator = DayLocator(interval=int(math.ceil(days/numticks)), tz=tz)
734+
fmt = '%b %d'
735+
elif hours>numticks:
736+
locator = HourLocator(interval=int(math.ceil(hours/numticks)), tz=tz)
737+
fmt = '%H:%M\n%b %d'
738+
elif minutes>numticks:
739+
locator = MinuteLocator(interval=int(math.ceil(minutes/numticks)), tz=tz)
740+
fmt = '%H:%M:%S'
741+
else:
742+
locator = MinuteLocator(tz=tz)
743+
fmt = '%H:%M:%S'
744+
745+
746+
formatter = DateFormatter(fmt, tz=tz)
747+
return locator, formatter
748+
706749
__all__ = ( 'date2num', 'num2date', 'drange', 'epoch2num',
707750
'num2epoch', 'mx2num', 'DateFormatter',
708751
'IndexDateFormatter', 'DateLocator', 'RRuleLocator',
@@ -711,3 +754,4 @@ def mx2num(mxdates):
711754
'SecondLocator', 'rrule', 'MO', 'TU', 'WE', 'TH', 'FR',
712755
'SA', 'SU', 'YEARLY', 'MONTHLY', 'WEEKLY', 'DAILY',
713756
'HOURLY', 'MINUTELY', 'SECONDLY', 'relativedelta')
757+

0 commit comments

Comments
 (0)