def add_plot_date(self, dates, values, format=None, xlabel=None, ylabel=None, bClear=True, titlePlot='Title', legend='Legend'): """ Наполняет график точками. @type dates: C{list | tuple} @param dates: Список дат в формате datetime. @type values: C{list | tuple} @param values: Список значений. @type dates: C{list | tuple} @param dates: Список дат в формате datetime. @type xlabel: C{string} @param xlabel: Подпись оси X. @type ylabel: C{string} @param ylabel: Подпись оси Y. @type bClear: C{bool} @param bClear: Признак того, что необходимо все предыдущие точки удалить из графика. @type titlePlot: C{string} @param titlePlot: Заголовок. @type legend: C{string} @param legend: Легенда. """ if bClear: self.subplot.lines = [] self.legendLst = [] matplotlib.rcParams['timezone'] = 'US/Pacific' tz = timezone('US/Pacific') majorTick = HourLocator(range(0, 25, 3), tz=tz) line = self.subplot.plot_date(dates, values, format, tz=tz) self.subplot.xaxis.set_major_locator(majorTick) # Устанавливаем легенду self.legendLst.append(legend) self.subplot.legend(self.subplot.lines, self.legendLst, 'upper right', shadow=True)
def set_date_plot2(self, date1=None, date2=None): """ """ # --- Plot2 matplotlib.rcParams['timezone'] = 'US/Pacific' tz = timezone('US/Pacific') date1 = datetime.datetime(2000, 3, 2, 10, tzinfo=tz) date2 = datetime.datetime(2000, 3, 2, 15, tzinfo=tz) delta = datetime.timedelta(minutes=5) dates = drange(date1, date2, delta) dd = 10 yy = pylab.arrayrange(len(dates) * 1.0) ysq = [y * y / dd for y in yy] self.add_plot_date(dates, ysq, 'b-o', u'Время', u'Цена') self.add_plot_date(dates, yy, 'r-d', bClear=False)
def set_date_plot2(self, date1=None, date2=None): """ """ # --- Plot2 matplotlib.rcParams['timezone'] = 'US/Pacific' tz = timezone('US/Pacific') if not date1: date1 = datetime.datetime(2000, 3, 2, 0, tzinfo=tz) else: date1 = datetime.datetime(date1[0], date1[1], date1[2], date1[3], tzinfo=tz) if not date2: date2 = datetime.datetime(2000, 3, 2, 23, tzinfo=tz) else: date2 = datetime.datetime(date2[0], date2[1], date2[2], date2[3], tzinfo=tz) delta = datetime.timedelta(minutes=20) dates = drange(date1, date2, delta) dd = 10 yy = pylab.arrayrange(len(dates) * 1.0) ysq = [y * y / dd for y in yy] self.add_plot_date(dates, ysq, 'bo', 'Время', 'Цена', legend='Скорость') self.add_plot_date(dates, yy, 'r-d', bClear=False) labels = self.subplot.get_xticklabels() pylab.set(labels, 'rotation', 45, size=10)
def add_plot_date(self, dates, values, format=None, xlabel=None, ylabel=None, bClear=True): """ Наполняет график точками. @type dates: C{list | tuple} @param dates: Список дат в формате datetime. @type values: C{list | tuple} @param values: Список значений. @type dates: C{list | tuple} @param dates: Список дат в формате datetime. @type xlabel: C{string} @param xlabel: Подпись оси X. @type ylabel: C{string} @param ylabel: Подпись оси Y. @type bClear: C{bool} @param bClear: Признак того, что необходимо все предыдущие точки удалить из графика. """ if bClear: self.subplot.lines = [] matplotlib.rcParams['timezone'] = 'US/Pacific' tz = timezone('US/Pacific') majorTick = HourLocator(range(0, 25, 1), tz=tz) line, = self.subplot.plot_date(dates, values, format, tz=tz) line.set_markersize(3) self.subplot.xaxis.set_major_locator(majorTick) if xlabel: self.subplot.set_xlabel(xlabel) if ylabel: self.subplot.set_ylabel(ylabel + '\n')
import matplotlib matplotlib.use('TkAgg') from matplotlib import matlab ML = matlab from matplotlib.dates import DayLocator, HourLocator, \ drange, date2num, timezone import datetime matplotlib.rcParams['timezone'] = 'US/Pacific' tz = timezone('US/Pacific') date1 = datetime.datetime( 2000, 3, 2, tzinfo=tz) date2 = datetime.datetime( 2000, 3, 6, tzinfo=tz) delta = datetime.timedelta(hours=6) dates = drange(date1, date2, delta) y = ML.arrayrange( len(dates)*1.0) ysq = y*y # note new constructor takes days or sequence of days you want to # tick, not the hour as before. Default is to tick every day majorTick = DayLocator(tz=tz) # the hour locator takes the hour or sequence of hours you want to # tick, not the base multiple minorTick = HourLocator(range(0,25,6), tz=tz) ax = ML.subplot(111) ax.plot_date(dates, ysq, tz=tz) # this is superfluous, since the autoscaler should get it right, but
def __init__(self, parent, id=-1, pos=(-1, -1), size=(-1, -1)): wx.Panel.__init__(self, parent, id, pos, size) self.count = 0 self.SetBackgroundColour(wx.NamedColor('WHITE')) self.figure = Figure() # --- dd = 10 # --- Plot2 matplotlib.rcParams['timezone'] = 'US/Pacific' tz = timezone('US/Pacific') date1 = datetime.datetime(2000, 3, 2, 10, tzinfo=tz) date2 = datetime.datetime(2000, 3, 2, 15, tzinfo=tz) delta = datetime.timedelta(minutes=5) dates = drange(date1, date2, delta) self.axes1 = self.figure.add_subplot(111) yy = pylab.arrayrange(len(dates) * 1.0) majorTick = HourLocator(range(0, 25, 1), tz=tz) ysq = [y * y / dd for y in yy] line = self.axes1.plot_date(dates, ysq, tz=tz) self.axes1.xaxis.set_major_locator(majorTick) self.axes1.set_xlabel('Time (s)') self.axes1.set_ylabel('Price 2 ($)') # self.canvas = FigureCanvas(self, -1, self.figure) self.canvas.mpl_connect('motion_notify_event', self.mouse_move) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) self.SetSizer(self.sizer) # --- Add Toolbar self.toolbar = Toolbar(self.canvas) self.toolbar.Realize() # On Windows, default frame size behaviour is incorrect # you don't need this under Linux tw, th = self.toolbar.GetSizeTuple() fw, fh = self.canvas.GetSizeTuple() self.toolbar.SetSize(wx.Size(fw, th)) # Create a figure manager to manage things self.figmgr = FigureManager(self.canvas, 1, self) self.sizer.Add(self.toolbar, 0, wx.EXPAND) self.toolbar.update() self.statusBar = wx.StatusBar(self, -1) self.statusBar.SetFieldsCount(1) self.sizer.Add(self.statusBar, 0, wx.EXPAND) self.Fit() # --- Обработчики событий self.Bind(wx.EVT_PAINT, self.OnPaint)