)Uc'@sdZddlZddlZddlZddlZddlZddlZddlj Z ddl j Z ddl j Z ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlmZddl Z!dmZ"d,ej#fd-YZ$e$Z%d.Z&d/Z'd0e'Z(d0e(Z)d1e)Z*d2Z+d3Z,e,d4Z-e-d5Z.eeeeeeef\Z/Z0Z1Z2Z3Z4Z5e/e0e1e2e3e4e5fZ6d6Z7dd7Z9d8dnd9YZ:d:Z;d;Z<d<Z=d=Z>dd>Z?d?Z@d e jAfd@YZBd e jAfdAYZCd e jAfdBYZDdCdodDYZEde jFfdEYZGdeGfdFYZHdeGfdGYZIdeGfdHYZJdeHfdIYZKdeHfdJYZLdeHfdKYZMdeHfdLYZNdeHfdMYZOdeHfdNYZPdOdPZQdOdQZRdRZSdSZTdTZUddOdUZVdVZWdWZXdXZYdYZZdZe j[fd[YZ\e\e j]ej^`_ uses a calendar that switches from Julian to Gregorian in October, 1582. Hence, using their calculator, the number of days between 0001-01-01 and 2006-04-01 is 732403, whereas using the Gregorian calendar via the datetime module we find:: In [31]:date(2006,4,1).toordinal() - date(1,1,1).toordinal() Out[31]:732401 A wide range of specific and general purpose date tick locators and formatters are provided in this module. See :mod:`matplotlib.ticker` for general information on tick locators and formatters. These are described below. All the matplotlib date converters, tickers and formatters are timezone aware, and the default timezone is given by the timezone parameter in your :file:`matplotlibrc` file. If you leave out a :class:`tz` timezone instance, the default from your rc file will be assumed. If you want to use a custom time zone, pass a :class:`pytz.timezone` instance with the tz keyword argument to :func:`num2date`, :func:`plot_date`, and any custom date tickers or locators you create. See `pytz `_ for information on :mod:`pytz` and timezone handling. The `dateutil module `_ provides additional code to handle date ticking, making it easy to place ticks on any kinds of dates. See examples below. Date tickers ------------ Most of the date tickers can locate single or multiple values. For example:: # tick on mondays every week loc = WeekdayLocator(byweekday=MO, tz=tz) # tick on mondays and saturdays loc = WeekdayLocator(byweekday=(MO, SA)) In addition, most of the constructors take an interval argument:: # tick on mondays every second week loc = WeekdayLocator(byweekday=MO, interval=2) The rrule locator allows completely general date ticking:: # tick every 5th easter rule = rrulewrapper(YEARLY, byeaster=1, interval=5) loc = RRuleLocator(rule) Here are all the date tickers: * :class:`MinuteLocator`: locate minutes * :class:`HourLocator`: locate hours * :class:`DayLocator`: locate specifed days of the month * :class:`WeekdayLocator`: Locate days of the week, eg MO, TU * :class:`MonthLocator`: locate months, eg 7 for july * :class:`YearLocator`: locate years that are multiples of base * :class:`RRuleLocator`: locate using a :class:`matplotlib.dates.rrulewrapper`. The :class:`rrulewrapper` is a simple wrapper around a :class:`dateutils.rrule` (`dateutil `_) which allow almost arbitrary date tick specifications. See `rrule example <../examples/pylab_examples/date_demo_rrule.html>`_. * :class:`AutoDateLocator`: On autoscale, this class picks the best :class:`MultipleDateLocator` to set the view limits and the tick locations. Date formatters --------------- Here all all the date formatters: * :class:`AutoDateFormatter`: attempts to figure out the best format to use. This is most useful when used with the :class:`AutoDateLocator`. * :class:`DateFormatter`: use :func:`strftime` format strings * :class:`IndexDateFormatter`: date plots with implicit *x* indexing. iN(trruletMOtTUtWEtTHtFRtSAtSUtYEARLYtMONTHLYtWEEKLYtDAILYtHOURLYtMINUTELYtSECONDLY(t relativedeltatdate2numtnum2datetdranget epoch2numt num2epochtmx2numt DateFormattertIndexDateFormattertAutoDateFormattert DateLocatort RRuleLocatortAutoDateLocatort YearLocatort MonthLocatortWeekdayLocatort DayLocatort HourLocatort MinuteLocatort SecondLocatorRRRRRRRRRR R R R R RRtsecondstminutesthourstweekst_UTCcBs)eZdZdZdZdZRS(tUTCcCs tjdS(Ni(tdatetimet timedelta(tselftdt((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyt utcoffsetscCsdS(NR(((R+R,((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyttznamescCs tjdS(Ni(R)R*(R+R,((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pytdsts(t__name__t __module__t__doc__R-R.R/(((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyR's  cCs6tjd}|dkrtSddl}|j|S(NttimezoneR(i(t matplotlibtrcParamsR(tpytzR3(tsR6((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyt_get_rc_timezones    g8@gN@g.Ai<iiicCst|drL|jdk rL|jj|}|dk rL||8}qLnt|j}t|dr||jt|jt |j t |j t 7}n|S(s Convert :mod:`datetime` to the Gregorian date as UTC float days, preserving hours, minutes, seconds and microseconds. Return value is a :func:`float`. ttzinfothourN(thasattrR9tNoneR-tfloatt toordinalR:t HOURS_PER_DAYtminutetMINUTES_PER_DAYtsecondtSECONDS_PER_DAYt microsecondtMUSECONDS_PER_DAY(R,tdeltatbase((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyt _to_ordinalfs 2c Cs.|d krt}nt|}tjj|}t||}td|d\}}td|d\}}td|d\}}td|}|dkrd}ntj|j|j|j t|t|t||dt j |}|dkr*|tj d d|7}n|S( s Convert Gregorian float of the date, preserving hours, minutes, seconds and microseconds. Return value is a :class:`datetime`. iii<g.Ai iR9i6Bt microsecondsN( R<R8tintR)t fromordinalR=tdivmodtyeartmonthtdayR(t astimezoneR*( txttztixR,t remainderR:R@RBRD((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyt_from_ordinalfs"   - t strpdate2numcBs eZdZdZdZRS(s Use this class to parse date strings to matplotlib datenums when you know the date format string of the date you are parsing. See :file:`examples/load_demo.py`. cCs ||_dS(s- fmt: any valid strptime format is supported N(tfmt(R+RW((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyt__init__scCs&ttjtj||jd S(sMs : string to be converted return value: a date2num float i(RR)ttimetstrptimeRW(R+R7((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyt__call__s(R0R1R2RXR[(((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRVs cCsXtj|r+tjj|}t|Stg|D]}tjj|^q5SdS(s Convert a date string to a datenum using :func:`dateutil.parser.parse`. *d* can be a single string or a sequence of strings. N(tcbooktis_string_liketdateutiltparsertparseR(tdR,R7((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyt datestr2nums cCsCtj|st|Stjg|D]}t|^q&SdS(s *d* is either a :class:`datetime` instance or a sequence of datetimes. Return value is a floating point number (or sequence of floats) which gives the number of days (fraction part represents hours, minutes, seconds) since 0001-01-01 00:00:00 UTC, *plus* *one*. The addition of one here is a historical artifact. Also, note that the Gregorian calendar is assumed; this is not universal practice. For details, see the module docstring. N(R\titerableRHtnptasarray(Ratval((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRs  cCs)tj|r!tj|}n|dS(sGConvert a Julian date (or sequence) to a matplotlib date (or sequence).gPD:A(R\RcRdRe(tj((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyt julian2numscCs)tj|r!tj|}n|dS(sGConvert a matplotlib date (or sequence) to a Julian date (or sequence).gPD:A(R\RcRdRe(tn((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyt num2julian scCsX|dkrt}ntj|s4t||Sg|D]}t||^q;SdS(s *x* is a float value which gives the number of days (fraction part represents hours, minutes, seconds) since 0001-01-01 00:00:00 UTC *plus* *one*. The addition of one here is a historical artifact. Also, note that the Gregorian calendar is assumed; this is not universal practice. For details, see the module docstring. Return value is a :class:`datetime` instance in timezone *tz* (default to rcparams TZ value). If *x* is a sequence, a sequence of :class:`datetime` objects will be returned. N(R<R8R\RcRU(RQRRRf((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRs   cCsJ|j|jt|jt}t|}t|}tj|||S(s Return a date range as float Gregorian ordinals. *dstart* and *dend* are :class:`datetime` instances. *delta* is a :class:`datetime.timedelta` instance. (tdaysR#RCRIRERHRdtarange(tdstarttdendRFtsteptf1tf2((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyR$s   cBsPeZdZejdZddZddZdZ dZ dZ RS( sY Tick location is seconds since the epoch. Use a :func:`strftime` format string. Python only supports :mod:`datetime` :func:`strftime` formatting for years greater than 1900. Thanks to Andrew Dalke, Dalke Scientific Software who contributed the :func:`strftime` code below to include dates earlier than this year. s((^|[^%])(%%)*%s)cCs.|dkrt}n||_||_dS(sl *fmt* is an :func:`strftime` format string; *tz* is the :class:`tzinfo` instance. N(R<R8RWRR(R+RWRR((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRXCs  icCs@|dkrtdnt||j}|j||jS(NisDateFormatter found a value of x=0, which is an illegal date. This usually occurs because you have not informed the axis that it is plotting dates, eg with ax.xaxis_date()(t ValueErrorRRRtstrftimeRW(R+RQtposR,((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyR[Ls cCs ||_dS(N(RR(R+RR((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyt set_tzinfoRscCsOg}d}x<|j||}|dkr1Pn|j||d}q|S(Niii(tfindtappend(R+ttexttsubstrtsitestiRg((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyt_findallUs   cCs|jjd|}|jdd}|jdkrLtj|j|S|j}d|}d|d|d}||}|d|d d }|j}tj||f|d }|j |t |}tj||d f|d } |j | t |d } g} x*|D]"} | | kr | j | q q W|} d |jf}x(| D] } | | || | d } qcWtj| S( Ns\1s%sR7iliiidiiis%4di( t illegal_stsubtreplaceRMR\t unicode_safeRst timetupleRYR|tstrRw(R+R,RWRMRFtoffRts1tsites1ts2tsites2RztsiteR7tsyear((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRsfs.    !   N( R0R1R2tretcompileR}R<RXR[RuR|Rs(((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyR6s    cBs&eZdZddZddZRS(sa Use with :class:`~matplotlib.ticker.IndexLocator` to cycle format strings by index. cCs7|dkrt}n||_||_||_dS(sw *t* is a sequence of dates (floating point days). *fmt* is a :func:`strftime` format string. N(R<R8ttRWRR(R+RRWRR((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRXs    icCsitt|}|t|jks3|dkr7dSt|j||j}tj|j|j S(s/Return the label for time *x* at position *pos*it( RJtroundtlenRRRRR\RRsRW(R+RQRttindR,((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyR[s !N(R0R1R2R<RXR[(((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRs cBs)eZdZdddZddZRS(s This class attempts to figure out the best format to use. This is most useful when used with the :class:`AutoDateLocator`. The AutoDateFormatter has a scale dictionary that maps the scale of the tick (the distance in days between one major tick) and a format string. The default looks like this:: self.scaled = { 365.0 : '%Y', 30. : '%b %Y', 1.0 : '%b %d %Y', 1./24. : '%H:%M:%D', } The algorithm picks the key in the dictionary that is >= the current scale and uses that format string. You can customize this dictionary by doing:: formatter = AutoDateFormatter() formatter.scaled[1/(24.*60.)] = '%M:%S' # only show min and sec s%Y-%m-%dcCs]||_||_||_t|j||_idd6dd6dd6ddd6|_d S( s} Autofmt the date labels. The default format is the one to use if none of the times in scaled match s%Ygv@s%b %Yg>@s%b %d %Yg?s%H:%M:%Sg8@N(t_locatort_tzt defaultfmtRt _formattertscaled(R+tlocatorRRR((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRXs   icCszt|jj}|j}x4t|jD]#}||kr.|j|}Pq.q.Wt||j|_|j||S(N( R=Rt _get_unitRtsortedRRRR(R+RQRttscaleRWtk((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyR[s   N(R0R1R2R<RXR[(((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRs t rrulewrappercBs#eZdZdZdZRS(cKs2|j|_||jdi(RRtabs(R+RRtunittinterval((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyt nonsingulars   N( R0R1thms0dR<RXRuRRRRR(((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRs      cBsMeZddZdZdZdZeeZdZdZ RS(cCstj||||_dS(N(RRXtrule(R+toRR((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRX&sc Csy|j\}}Wntk r*gSX||krG||}}nt||}y||}Wntk rtd}nXy||}Wntk rtd}nX|jjd|d|d|jdt||f\}}|||j|j }||jdkrGt d||||jdfn|jj ||t } t | d krt||gS|jt| S( Ng?g)KAtdtstarttuntiltcountiis]RRuleLocator estimated to generate %d ticks from %s to %s: exceeds Locator.MAXTICKS * 2 (%d) i(RRrRRURRtMAXTICKSRRRt RuntimeErrortbetweentTrueRtraise_if_exceeds( R+RRRFtstarttstoptnmaxtnmintestimatetdates((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyR[*s2    &#cCs|jjj}|j|S(sj Return how many days a unit of the locator is; used for intelligent autoscaling. (RRt_freqtget_unit_generic(R+R((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRQscCs|tkrdS|tkr dS|tkr0dS|tkr@dS|tkrTddS|tkrhdd S|tkr|dd Sd SdS( Ngv@g>@g@g?g8@ii<iiiiQ(RR R R R R R(R((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRYs       cCs |jjjS(N(RRt _interval(R+((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRmscCs4|j\}}||kr.||}}nt||}y||}Wntk rjtd}nXy||}Wntk rtd}nX|jjd|d||j\}}|jj|t}|s|}n|jj|t}|s |}nt |}t |}|j ||S(s@ Set the view limits to include the data range. g?g)KARR( RRRrRURRtbeforeRtafterRR(R+RRRFRRRR((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyt autoscaleps.       N( R0R1R<RXR[RRt staticmethodRR(((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyR#s  '    cBsYeZdZd dd edZdZdZdZdZ dZ dZ RS( s On autoscale, this class picks the best :class:`MultipleDateLocator` to set the view limits and the tick locations. icCstj||t|_t|_ttttt t g|_ ||_ idt6dt6dt6dt6dt 6dt 6|_ |dk ry|j j|Wqtk rtt|j |gt|j |_ qXn||_idddddgt6ddd dd gt6ddd d d gt6ddd dd dgt6dddd dgt 6dddd dgt 6|_dtddtddtddtddtddg|_dS(s *minticks* is the minimum number of ticks desired, which is used to select the type of ticking (yearly, monthly, etc.). *maxticks* is the maximum number of ticks desired, which controls any interval between ticks (ticking every other, every 3, etc.). For really fine-grained control, this can be a dictionary mapping individual rrule frequency constants (YEARLY, MONTHLY, etc.) to their own maximum number of ticks. This can be used to keep the number of ticks appropriate to the format chosen in class:`AutoDateFormatter`. Any frequency not specified in this dictionary is given a default value. *tz* is a :class:`tzinfo` instance. *interval_multiples* is a boolean that indicates whether ticks should be chosen to be multiple of the interval. This will lock ticks to 'nicer' locations. For example, this will force the ticks to be at hours 0,6,12,18 when hourly ticking is done at 6 hour intervals. The AutoDateLocator has an interval dictionary that maps the frequency of the tick (a constant from dateutil.rrule) and a multiple allowed for that ticking. The default looks like this:: self.intervald = { YEARLY : [1, 2, 4, 5, 10], MONTHLY : [1, 2, 3, 4, 6], DAILY : [1, 2, 3, 7, 14], HOURLY : [1, 2, 3, 4, 6, 12], MINUTELY: [1, 5, 10, 15, 30], SECONDLY: [1, 5, 10, 15, 30] } The interval is used to specify multiples that are appropriate for the frequency of ticking. For instance, every 7 days is sensible for daily ticks, but for minutes/seconds, 15 or 30 make sense. You can customize this dictionary by doing:: locator = AutoDateLocator() locator.intervald[HOURLY] = [3] # only show every 3 hours ii i iiiii iiiiiii i iii<N(RRXRRRRR R R R Rt_freqstmintickstmaxticksR<Rt TypeErrortdicttzipRtinterval_multiplest intervaldtranget _byranges(R+RRRRR((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRXs.,      & 'cCs|j|jS(s!Return the locations of the ticks(trefreshR(R+((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyR[s cCs$tj|||jj|dS(N(Rtset_axisR(R+R((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRscCs+|j\}}|j|||_dS(s5Refresh internal information based on current limits.N(Rt get_locatorR(R+RR((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRscCstj|jS(N(RRR(R+((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRscCs4|j\}}|j|||_|jjS(s,Try to choose the view limits intelligently.(RRRR(R+RR((sC/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/dates.pyRscCsNt||}|jd}|d|j}|d|j}|d|j}|d|j}|d|j} |||||| g} ddddddg} xtt |j | D]\} \} }||j krd| | ms0  d        0       TG)s8     *    6 '