Changeset 3038


Ignore:
Timestamp:
06/29/15 18:52:29 (9 years ago)
Author:
Kana Sugimoto
Message:

New Development: No

JIRA Issue: No (a bug fix)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: added axlim parameter (optional) to asapplotter._get_date_axis_setup.

Test Programs: runUnitTest.main(test_sdplot[test_totalpowerCflag])

Put in Release Notes: No

Module(s): asapplotter, sdplot

Description: Fixed a bug in tick interval for > 1year


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapplotter.py

    r3016 r3038  
    13171317            return start,end
    13181318
    1319     def _get_date_axis_setup(self, dates):
     1319    def _get_date_axis_setup(self, dates, axlim=None):
    13201320        """
    13211321        Returns proper axis title and formatters for a list of dates
     
    13231323            dates : a list of datetime objects returned by,
    13241324                    e.g. scantable.get_time(asdatetime=True)
     1325            axlim : a tuple of min and max day range in the plot axis.
     1326                    if defined, the values are taken into account.
    13251327        Output
    13261328            a set of
     
    13321334        from matplotlib import pylab as PL
    13331335        from matplotlib.dates import DateFormatter
    1334         from matplotlib.dates import HourLocator, MinuteLocator,SecondLocator, DayLocator
     1336        from matplotlib.dates import HourLocator, MinuteLocator,SecondLocator, DayLocator, YearLocator, MonthLocator
    13351337        t = PL.date2num(dates)
    1336         tdel = max(t) - min(t) # interval in day
     1338        tmin = min(t)
     1339        tmax = max(t)
     1340        if axlim is not None:
     1341            tmin = min(tmin, min(axlim))
     1342            tmax = max(tmax, max(axlim))
     1343        tdel = tmax - tmin # interval in day
    13371344        dstr = dates[0].strftime('%Y/%m/%d')
    1338         if tdel > 1.0: # >1day
     1345        if tdel > 365.0: # >1year (also the case for single or very small time range)
     1346            majloc = YearLocator()
     1347            minloc = MonthLocator(range(1,12,6))
     1348            timefmt = DateFormatter('%Y/%m/%d')
     1349        elif tdel > 1.0: # >1day
    13391350            dstr2 = dates[len(dates)-1].strftime('%Y/%m/%d')
    13401351            dstr = dstr + " - " + dstr2
     
    18091820
    18101821        # legend and axis formatting
    1811         (dstr, timefmt, majloc, minloc) = self._get_date_axis_setup(alldates)
    18121822        ax = self.gca()
     1823        (dstr, timefmt, majloc, minloc) = self._get_date_axis_setup(alldates, ax.get_xlim())
    18131824        ax.xaxis.set_major_formatter(timefmt)
    18141825        ax.xaxis.set_major_locator(majloc)
Note: See TracChangeset for help on using the changeset viewer.