def _init_ctrls(self, prnt): #matplotlib.figure.Figure.__init__(self) wx.Panel.__init__(self, prnt, -1) self.figure = matplotlib.figure.Figure() self.plot = self.figure.add_subplot(111) self.plot.axis([0, 1, 0, 1]) # self.plot.plot([], []) self.plot.set_title("No Data To Plot") self.canvas = FigCanvas(self, -1, self.figure) # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas) self.toolbar.Realize() #self.canvas.SetCursor(wx.StockCursor(wx.CURSOR_CROSS)) #self.canvas.SetScrollbar(wx.HORIZONTAL, 0,5, 1000) self.SetColor("WHITE") self.canvas.SetFont( wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.fontP = FontProperties() self.fontP.set_size('small') self.canvas.draw() self._init_sizers()
def _init_ctrls(self, prnt): # matplotlib.figure.Figure.__init__(self) wx.Panel.__init__(self, prnt, -1) Publisher.subscribe(self.monthly, ("box.Monthly")) Publisher.subscribe(self.yearly, ("box.Yearly")) Publisher.subscribe(self.seasonaly, ("box.Seasonal")) Publisher.subscribe(self.overall, ("box.Overall")) self.figure = Figure() # self.figure = plt.figure() plot = self.figure.add_subplot(111) #self.plot.axis([0, 1, 0, 1]) # plot.set_title("No Data To Plot") self.canvas = FigCanvas(self, -1, self.figure) # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, True) self.toolbar.Realize() self.figure.tight_layout() self.setColor("WHITE") self.canvas.SetFont( wx.Font(15, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.canvas.draw() self._init_sizers()
def _init_ctrls(self, prnt): #matplotlib.figure.Figure.__init__(self) wx.Panel.__init__(self, prnt, -1) self.figure = matplotlib.figure.Figure() self.plot=self.figure.add_subplot(111) self.plot.set_title("No Data To Plot") self.canvas = FigCanvas(self, -1, self.figure) # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, True) self.toolbar.Realize() self.SetColor("WHITE") self.canvas.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.canvas.draw() self._init_sizers() self.hist=[] self.bins=50
def _init_ctrls(self, parent): wx.Panel.__init__(self, parent, -1) self.parent = parent #init Plot # matplotlib.figure.Figure self.figure = plt.figure() # matplotlib.axes.AxesSubplot self.timeSeries = host_subplot( 111, axes_class=AA.Axes) self.setTimeSeriesTitle("No Data to Plot") # matplotlib.backends.backend_wxagg.FigureCanvasWxAgg self.canvas = FigCanvas(self, -1, self.figure) self.canvas.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.isShowLegendEnabled = False # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, allowselect=True) self.canvas.mpl_connect('figure_leave_event', self.toolbar._onFigureLeave) Publisher.subscribe(self.updateCursor, "updateCursor") self.toolbar.Realize() self.seriesPlotInfo = None #set properties self.fontP = FontProperties() self.fontP.set_size('x-small') self.format = '-o' self.alpha=1 self._setColor("WHITE") left = 0.125 # the left side of the subplots of the figure plt.subplots_adjust( left=left#, bottom=bottom, right=right, top=top, wspace=wspace, hspace=hspace ) plt.tight_layout() #init lists #self.lines = {} self.lines = [] self.axislist = {} self.curveindex = -1 self.editseriesID = -1 self.editCurve = None self.editPoint =None # self.hoverAction = None self.selplot= None self.cursors = [] self.canvas.draw() self._init_sizers()
def _init_ctrls(self, parent): wx.Panel.__init__(self, parent, -1) self.parent = parent #init Plot # matplotlib.figure.Figure self.figure = plt.figure() # matplotlib.axes.AxesSubplot self.timeSeries = host_subplot(111, axes_class=AA.Axes) self.setTimeSeriesTitle("No Data to Plot") # matplotlib.backends.backend_wxagg.FigureCanvasWxAgg self.canvas = FigCanvas(self, -1, self.figure) self.canvas.SetFont( wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.isShowLegendEnabled = False # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, allowselect=True) self.canvas.mpl_connect('figure_leave_event', self.toolbar._onFigureLeave) Publisher.subscribe(self.updateCursor, "updateCursor") self.toolbar.Realize() self.seriesPlotInfo = None #set properties self.fontP = FontProperties() self.fontP.set_size('x-small') self.format = '-o' self.alpha = 1 self._setColor("WHITE") left = 0.125 # the left side of the subplots of the figure plt.subplots_adjust( left= left #, bottom=bottom, right=right, top=top, wspace=wspace, hspace=hspace ) plt.tight_layout() #init lists #self.lines = {} self.lines = [] self.axislist = {} self.curveindex = -1 self.editseriesID = -1 self.editCurve = None self.editPoint = None # self.hoverAction = None self.selplot = None self.cursors = [] self.canvas.draw() self._init_sizers()
def _init_ctrls(self, parent): #matplotlib.figure.Figure.__init__(self) wx.Panel.__init__(self, parent, -1) self.parent = parent # self.figure = Figure()#matplotlib.figure.Figure() #init Plot # self.timeSeries=self.figure.add_subplot(111) self.timeSeries = host_subplot(111, axes_class=AA.Axes) # self.timeSeries.axis([0, 1, 0, 1])# self.timeSeries.plot([],[]) self.timeSeries.set_title("No Data To Plot") self.canvas = FigCanvas(self, -1, plt.gcf()) # self.canvas = FigCanvas(self, -1, self.figure) self.canvas.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) # self.canvas.mpl_connect('pick_event', self.on_pick) # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, allowselect=True) self.toolbar.Realize() self.seriesPlotInfo= None self.fontP = FontProperties() self.fontP.set_size('small') self.format = '-o' self.SetColor("WHITE") #self.canvas.gca().xaxis.set_major_locator() #init lists self.lines=[] self.axislist={} self.curveindex = -1 self.editseriesID = -1 self.editCurve =None self.cid=None self.canvas.draw() self._init_sizers()
def _init_ctrls(self, prnt): #matplotlib.figure.Figure.__init__(self) wx.Panel.__init__(self, prnt, -1) self.figure = Figure() ax = self.figure.add_subplot(111) ax.axis([0, 1, 0, 1]) # ax.plot([], []) ax.set_title("No Data To Plot") self.islegendvisible = False self.canvas = FigCanvas(self, -1, self.figure) # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas) self.toolbar.Realize() self.axislist = {} left = 0.125 # the left side of the subplots of the figure right = 0.9 # the right side of the subplots of the figure bottom = 0.51 # the bottom of the subplots of the figure top = 1.2 # the top of the subplots of the figure wspace = .8 # the amount of width reserved for blank space between subplots hspace = .8 # the amount of height reserved for white space between subplots self.figure.subplots_adjust(left=left, bottom=bottom, right=right, top=top, wspace=wspace, hspace=hspace) self.figure.tight_layout() #self.canvas.SetCursor(wx.StockCursor(wx.CURSOR_CROSS)) #self.canvas.SetScrollbar(wx.HORIZONTAL, 0,5, 1000) self.setColor("WHITE") self.canvas.SetFont( wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.fontP = FontProperties() self.fontP.set_size('small') self.canvas.draw() self._init_sizers()
class plotBox(wx.Panel): def _init_coll_boxSizer1_Items(self, parent): # generated method, don't edit parent.AddWindow(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) parent.AddWindow(self.toolbar, 0, wx.EXPAND) def _init_sizers(self): # generated method, don't edit self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL) self._init_coll_boxSizer1_Items(self.boxSizer1) self.SetSizer(self.boxSizer1) def _init_ctrls(self, prnt): #matplotlib.figure.Figure.__init__(self) wx.Panel.__init__(self, prnt, -1) Publisher.subscribe(self.monthly, ("box.Monthly")) Publisher.subscribe(self.yearly, ("box.Yearly")) Publisher.subscribe(self.seasonaly, ("box.Seasonal")) Publisher.subscribe(self.overall, ("box.Overall")) self.figure = matplotlib.figure.Figure() self.plot = self.figure.add_subplot(111) self.plot.axis([0, 1, 0, 1]) # self.plot.set_title("No Data To Plot") self.canvas = FigCanvas(self, -1, self.figure) # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, True) self.toolbar.Realize() #self.canvas.SetCursor(wx.StockCursor(wx.CURSOR_CROSS)) #self.canvas.SetScrollbar(wx.HORIZONTAL, 0,5, 1000) self.SetColor("WHITE") self.canvas.SetFont( wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.canvas.draw() self._init_sizers() def Clear(self): self.figure.clear() def GridSize(self, cells): rows = 1 cols = 1 while rows * cols < cells: if rows == cols: cols = cols + 1 else: rows = rows + 1 return rows, cols def textSize(self, cells): wrap = 50 wrap = wrap - (cells * 3) text = 20 - cells return wrap, text def Plot(self, seriesPlotInfo): self.seriesPlotInfo = seriesPlotInfo self.updatePlot() def updatePlot(self): self.Clear() count = self.seriesPlotInfo.count() rows, cols = self.GridSize(count) self.plots = [] i = 1 for oneSeries in self.seriesPlotInfo.GetSeriesInfo(): self.plots.append( self.figure.add_subplot(repr(rows) + repr(cols) + repr(i))) wrap, text = self.textSize(count) self.plots[i - 1].set_xlabel("\n".join( textwrap.wrap(oneSeries.BoxWhisker.currinterval.title, wrap))) self.plots[i - 1].set_ylabel("\n".join( textwrap.wrap( oneSeries.variableName + "(" + oneSeries.variableUnits + ")", wrap))) self.plots[i - 1].set_title("\n".join( textwrap.wrap( oneSeries.siteName + " " + oneSeries.variableName, wrap))) self.canvas.SetFont( wx.Font(text, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) med = oneSeries.BoxWhisker.currinterval.medians cl = oneSeries.BoxWhisker.currinterval.confint mean = oneSeries.BoxWhisker.currinterval.means ci = oneSeries.BoxWhisker.currinterval.conflimit bp = self.plots[i - 1].boxplot( oneSeries.BoxWhisker.currinterval.data, sym="-gs", notch=True, bootstrap=5000, conf_intervals=cl) # Plot Mean and its confidence interval for x in range(len(mean)): self.plots[i - 1].vlines(x + 1, ci[x][0], ci[x][1], color='r', linestyle="solid") self.plots[i - 1].scatter([range(1, len(mean) + 1)], mean, marker='o', c='r', s=10) # Plot Median self.plots[i - 1].scatter([range(1, len(med) + 1)], med, marker='s', c="k", s=10) # Set Colors of the Box Whisker plot plt.setp(bp['whiskers'], color='k', linestyle='-') plt.setp(bp['medians'], color='k', linestyle='-') plt.setp(bp['boxes'], color='GREY', linestyle='-') plt.setp(bp['caps'], color='k') plt.setp(bp['fliers'], markersize=3.5) # self.plot.set_ybound(min(data),max(data)) self.plots[i - 1].set_autoscale_on(True) self.plots[i - 1].set_xticklabels( oneSeries.BoxWhisker.currinterval.xlabels) i = i + 1 self.canvas.draw() def SetColor(self, color): # """Set figure and canvas colours to be the same.""" self.figure.set_facecolor(color) self.figure.set_edgecolor(color) self.canvas.SetBackgroundColour(color) def monthly(self, str): # print "monthly" self.seriesPlotInfo.SetBoxInterval("Monthly") self.updatePlot() def seasonaly(self, str): # print"seasonal" self.seriesPlotInfo.SetBoxInterval("Seasonally") self.updatePlot() def yearly(self, str): # print "yearly" self.seriesPlotInfo.SetBoxInterval("Yearly") self.updatePlot() def overall(self, str): # print "overall" self.seriesPlotInfo.SetBoxInterval("Overall") self.updatePlot() def __init__(self, parent, id, pos, size, style, name): self._init_ctrls(parent)
class plotHist(wx.Panel): def _init_coll_boxSizer1_Items(self, parent): # generated method, don't edit parent.AddWindow(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) parent.AddWindow(self.toolbar, 0, wx.EXPAND) def _init_sizers(self): # generated method, don't edit self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL) self._init_coll_boxSizer1_Items(self.boxSizer1) self.SetSizer(self.boxSizer1) def _init_ctrls(self, prnt): #matplotlib.figure.Figure.__init__(self) wx.Panel.__init__(self, prnt, -1) self.figure = matplotlib.figure.Figure() self.plot=self.figure.add_subplot(111) self.plot.set_title("No Data To Plot") self.canvas = FigCanvas(self, -1, self.figure) # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, True) self.toolbar.Realize() self.SetColor("WHITE") self.canvas.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.canvas.draw() self._init_sizers() self.hist=[] self.bins=50 def ChangeNumOfBins(self, bins): self.bins = bins self.updatePlot() def Clear(self): self.figure.clear() self.hist=[] def GridSize(self, cells): rows = 1 cols = 1 while rows * cols < cells: if rows == cols: cols = cols + 1 else: rows = rows + 1 return rows, cols def textSize(self, cells): wrap = 50 wrap = wrap-(cells*3) text= 20 -cells return wrap, text def Plot(self, seriesPlotInfo): self.seriesPlotInfo= seriesPlotInfo self.updatePlot() def updatePlot(self): self.Clear() count = self.seriesPlotInfo.count() rows, cols = self.GridSize(count) self.plots=[] i=1 for oneSeries in self.seriesPlotInfo.GetSeriesInfo(): self.plots.append(self.figure.add_subplot(repr(rows)+repr(cols)+repr(i))) wrap, text = self.textSize(count) self.plots[i-1].set_xlabel("\n".join(textwrap.wrap(oneSeries.variableName,wrap))) self.plots[i-1].set_ylabel("Number of Observations") self.canvas.SetFont(wx.Font(text, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.plots[i-1].set_title("\n".join(textwrap.wrap(oneSeries.siteName+" "+oneSeries.variableName,wrap))) self.hist.append(self.plots[i-1].hist([x[0] for x in oneSeries.dataTable], bins=self.bins, normed=False, facecolor='g', alpha=0.75, label = oneSeries.siteName+" "+oneSeries.variableName)) i=i+1 self.canvas.draw() def SetColor( self, color): """Set figure and canvas colours to be the same.""" self.figure.set_facecolor( color ) self.figure.set_edgecolor( color ) self.canvas.SetBackgroundColour( color ) def __init__(self, parent, id, pos, size, style, name): self._init_ctrls(parent)
def _init_ctrls(self, parent): wx.Panel.__init__(self, parent, -1) self.parent = parent #init Plot # matplotlib.figure.Figure self.figure = plt.figure() # matplotlib.axes.AxesSubplot self.timeSeries = host_subplot( 111, axes_class=AA.Axes) self.setTimeSeriesTitle("No Data to Plot") # matplotlib.backends.backend_wxagg.FigureCanvasWxAgg self.canvas = FigCanvas(self, -1, self.figure) self.canvas.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.isShowLegendEnabled = False self.canvas.mpl_connect('figure_leave_event', self._onFigureLeave) Publisher.subscribe(self.updateCursor, "updateCursor") # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, allowselect=True) self.toolbar.Realize() self.seriesPlotInfo = None #set properties self.fontP = FontProperties() self.fontP.set_size('x-small') self.format = '-o' self.alpha=1 self._setColor("WHITE") left = 0.125 # the left side of the subplots of the figure #right = 0.9 # the right side of the subplots of the figure #bottom = 0.51 # the bottom of the subplots of the figure #top = 1.2 # the top of the subplots of the figure #wspace = .8 # the amount of width reserved for blank space between subplots #hspace = .8 # the amount of height reserved for white space between subplots plt.subplots_adjust( left=left#, bottom=bottom, right=right, top=top, wspace=wspace, hspace=hspace ) plt.tight_layout() #init hover tooltip # create a long tooltip with newline to get around wx bug (in v2.6.3.3) # where newlines aren't recognized on subsequent self.tooltip.SetTip() calls self.tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n') self.canvas.SetToolTip(self.tooltip) self.tooltip.Enable(False) self.tooltip.SetDelay(0) #init lists #self.lines = {} self.lines = [] self.axislist = {} self.curveindex = -1 self.editseriesID = -1 self.editCurve = None self.editPoint =None self.hoverAction = None self.selplot= None self.cursors = [] self.canvas.draw() self._init_sizers()
class plotTimeSeries(wx.Panel): def __init__(self, parent, id, pos, size, style, name): self._init_ctrls(parent) def _init_coll_boxSizer1_Items(self, parent): # generated method, don't edit parent.AddWindow(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) parent.AddWindow(self.toolbar, 0, wx.EXPAND) def _init_ctrls(self, parent): wx.Panel.__init__(self, parent, -1) self.parent = parent #init Plot # matplotlib.figure.Figure self.figure = plt.figure() # matplotlib.axes.AxesSubplot self.timeSeries = host_subplot( 111, axes_class=AA.Axes) self.setTimeSeriesTitle("No Data to Plot") # matplotlib.backends.backend_wxagg.FigureCanvasWxAgg self.canvas = FigCanvas(self, -1, self.figure) self.canvas.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.isShowLegendEnabled = False # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, allowselect=True) self.canvas.mpl_connect('figure_leave_event', self.toolbar._onFigureLeave) Publisher.subscribe(self.updateCursor, "updateCursor") self.toolbar.Realize() self.seriesPlotInfo = None #set properties self.fontP = FontProperties() self.fontP.set_size('x-small') self.format = '-o' self.alpha=1 self._setColor("WHITE") left = 0.125 # the left side of the subplots of the figure plt.subplots_adjust( left=left#, bottom=bottom, right=right, top=top, wspace=wspace, hspace=hspace ) plt.tight_layout() #init lists #self.lines = {} self.lines = [] self.axislist = {} self.curveindex = -1 self.editseriesID = -1 self.editCurve = None self.editPoint =None # self.hoverAction = None self.selplot= None self.cursors = [] self.canvas.draw() self._init_sizers() def _init_sizers(self): # generated method, don't edit self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL) self._init_coll_boxSizer1_Items(self.boxSizer1) self.SetSizer(self.boxSizer1) ## TODO 10/15/2014 Change function so that it will accept a list of datavalues. This will remove the need to loop through the values currently plotted and we would instead plot the list of datetimes and datavalues together. def changePlotSelection(self, filtered_datetime): """ Selected points have a scatter plot drawn over them to indicated the point being selected """ if self.selplot: self.selplot.remove() del self.selplot self.selplot = None result = None if isinstance(filtered_datetime, pd.DataFrame): result = filtered_datetime.sort_index() if isinstance(filtered_datetime, list): df = self.editCurve.dataTable result = df[df['LocalDateTime'].isin(filtered_datetime)].astype(datetime.datetime) if isinstance(result, pd.DataFrame): if result.empty: self.canvas.draw() return else: if not result: self.canvas.draw() return values = result['DataValue'].values.tolist() dates = result.index.astype(datetime.datetime) self.selplot = self.axislist[self.editSeries.axisTitle].scatter( dates, values, s=35, c='red', edgecolors='none', zorder=12, marker='s', alpha=1) self.canvas.draw() def lassoChangeSelection(self, filtered_datetime): self.parent.record_service.select_points(dataframe=filtered_datetime) def onShowLegend(self, isVisible): if isVisible: self.isShowLegendEnabled = True plt.subplots_adjust(bottom=.1 + .1) leg = self.timeSeries.legend(loc='upper right', ncol=2, fancybox=True, prop=self.fontP) leg.get_frame().set_alpha(.5) leg.draggable(state=True) else: self.isShowLegendEnabled = False plt.subplots_adjust(bottom=.1) self.timeSeries.legend_ = None plt.gcf().autofmt_xdate() self.canvas.draw() def onPlotType(self, ptype): # self.timeSeries.clear() if ptype == "line": ls = '-' m = 'None' elif ptype == "point": ls = 'None' m = 'o' else: ls = '-' m = 'o' self.format = ls + m for k, v in self.axislist.iteritems(): lines = v.get_lines() for line in lines: plt.setp(line, linestyle=ls, marker=m) if self.isShowLegendEnabled: self.onShowLegend(self.isShowLegendEnabled) plt.gcf().autofmt_xdate() self.canvas.draw() def stopEdit(self): self.clear() self.selectedlist = None self.selplot = None self.lman = None #self.canvas.mpl_disconnect(self.hoverAction) # try: # self.canvas.mpl_disconnect(self.pointPick) # self.pointPick = None # except AttributeError as e: # logger.error(e) # self.hoverAction = None self.xys = None self.alpha=1 self.curveindex = -1 self.editCurve = None # self.RefreshPlot() if self.seriesPlotInfo and self.seriesPlotInfo.isPlotted(self.editseriesID): self.updatePlot() self.toolbar.stopEdit() self.editseriesID = -1 def updateValues(self): # self.addEdit(self.editCursor, self.editSeries, self.editDataFilter) #clear current edit points and curve if self.editCurve: curraxis = self.axislist[self.editCurve.axisTitle] for l in curraxis.lines: if l.get_label() == self.editCurve.plotTitle: curraxis.lines.remove(l) #redraw editpoints and curve self.seriesPlotInfo.updateEditSeries() self.editCurve = self.seriesPlotInfo.getEditSeriesInfo() self.drawEditPlot(self.editCurve) self.canvas.draw() Publisher.sendMessage("refreshTable", e=self.editCurve.dataTable) # self.parent.parent.dataTable.Refresh() plt.gcf().autofmt_xdate() self.canvas.draw() def drawEditPlot(self, oneSeries): self.axislist[oneSeries.axisTitle].set_zorder(10) self.lines[self.curveindex] = self.axislist[oneSeries.axisTitle] data = oneSeries.dataTable dates = data.index.astype(datetime.datetime) curraxis = self.axislist[oneSeries.axisTitle] curraxis.plot_date(dates, data['DataValue'], "-s", color=oneSeries.color, xdate=True, label=oneSeries.plotTitle, zorder=10, alpha=1, picker=5.0, pickradius=5.0, markersize=4.5) curraxis.set_xlabel('Date') convertedDates = matplotlib.dates.date2num(dates) # scale = 1.5 # f = zoom_factory(curraxis , base_scale = scale) self.xys = zip(convertedDates, oneSeries.dataTable['DataValue']) self.toolbar.editSeries(self.xys, self.editCurve) # self.pointPick = self.canvas.mpl_connect('pick_event', self._onPick) self.editSeries = oneSeries def _setColor(self, color): """Set figure and canvas colours to be the same. :rtype : object """ plt.gcf().set_facecolor(color) plt.gcf().set_edgecolor(color) self.canvas.SetBackgroundColour(color) def close(self): #plt.clf() #plt.close() pass def Plot(self, seriesPlotInfo): self.seriesPlotInfo = seriesPlotInfo self.updatePlot() # resets the home view - will remove any previous zooming self.toolbar.update() self.toolbar.push_current() #self._views.home() #self._positions.home() #self.set_history_buttons() #clear plot def clear(self): """ :return: """ lines = [] for key, ax in self.axislist.items(): ax.clear() self.axislist = {} #self.canvas.draw() # self.stopEdit() #print "TimeSeries: ", dir(self.timeSeries), type(self.timeSeries) #plt.cla() #plt.clf() #self.timeSeries.plot([], [], picker=5) def setUpYAxis(self): """ Setting up multiple axes :return: """ self.axislist = {} left = 0 right = 0 adj = .05 editaxis = None ## Identify Axes and save them to axislist #loop through the list of curves and add an axis for each for oneSeries in self.seriesPlotInfo.getAllSeries(): #test to see if the axis already exists if oneSeries.edit: editaxis = oneSeries.axisTitle if not oneSeries.axisTitle in self.axislist: self.axislist[oneSeries.axisTitle] = None keys = self.axislist.keys() ## Put editing axis at the beginning of the list if editaxis: for i in range(len(keys)): if keys[i] == editaxis: keys.pop(i) break keys.insert(0, editaxis) leftadjust = -30 for i, axis in zip(range(len(self.axislist)), keys): if i % 2 == 0: left = left + 1 #add to the left(yaxis) if i == 0: #if first plot use the orig axis newAxis = self.timeSeries else: newAxis = self.timeSeries.twinx() ''' Spines idea #newAxis.spines["left"].set_position(("axes", leftadjust * left)) newAxis.spines["left"].set_position(("axes", -.1)) newAxis.spines["left"].set_visible(True) newAxis.yaxis.set_label_position("left") newAxis.yaxis.set_ticks_position("left") ''' new_fixed_axis = newAxis.get_grid_helper().new_fixed_axis newAxis.axis['left'] = new_fixed_axis(loc='left', axes=newAxis, offset=(leftadjust * left, 0)) newAxis.axis["left"].toggle(all=True) newAxis.axis["right"].toggle(all=False) leftadjust -= 15 else: right = right + 1 #add to the right(y2axis) newAxis = self.timeSeries.twinx() ''' Spines idea #newAxis.spines["right"].set_position(("axes", -1*60*(right - 1))) newAxis.spines["right"].set_position(("axes", 1.0)) newAxis.spines["right"].set_visible(True) newAxis.yaxis.set_label_position("right") newAxis.yaxis.set_ticks_position("right") ''' new_fixed_axis = newAxis.get_grid_helper().new_fixed_axis newAxis.axis['right'] = new_fixed_axis(loc='right', axes=newAxis, offset=(60 * (right - 1), 0)) newAxis.axis['right'].toggle(all=True) a = newAxis.set_ylabel(axis, picker=True) a.set_picker(True) #logger.debug("axis label: %s" % (axis)) self.axislist[axis] = newAxis plt.tight_layout() self.canvas.draw() def updatePlot(self): self.clear() count = self.seriesPlotInfo.count() self.setUpYAxis() self.lines = [] ## Spine initialization ## for oneSeries in self.seriesPlotInfo.getAllSeries(): if oneSeries.seriesID == self.seriesPlotInfo.getEditSeriesID(): """ Edited Series """ self.curveindex = len(self.lines) self.lines.append("") self.editCurve = oneSeries self.drawEditPlot(oneSeries) else: """ Plotted Series """ curraxis = self.axislist[oneSeries.axisTitle] curraxis.set_zorder(1) data = oneSeries.dataTable dates = data.index.astype(datetime.datetime) #data.plot(ax=curraxis) curraxis.plot_date(dates, data['DataValue'], color=oneSeries.color, fmt=self.format, xdate=True, tz=None, antialiased=True, label=oneSeries.plotTitle, alpha=self.alpha, picker=5.0, pickradius=5.0, markersize=4) curraxis.set_xlabel('Date') ''' data = oneSeries.dataTable #dates = data['LocalDateTime'].astype(datetime.datetime) data['LocalDateTime'] = pd.to_datetime(data['LocalDateTime']) data['LocalDateTime'].astype(datetime.datetime) data.plot(ax=curraxis) oneSeries.dataTable.plot(ax=curraxis) curraxis.set_xlabel('Date') ''' if count > 1: self.setTimeSeriesTitle("") plt.subplots_adjust(bottom=.1 + .1) # self.timeSeries.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), # ncol=2, prop = self.fontP) self.timeSeries.legend(loc='upper center', bbox_to_anchor=(0.5, -1.75), ncol=2, prop=self.fontP) elif count == 0: self.setTimeSeriesTitle("") self.timeSeries.legend_ = None else: self.setTimeSeriesTitle(oneSeries.siteName) plt.subplots_adjust(bottom=.1) self.timeSeries.legend_ = None self.timeSeries.set_xlabel("Date", picker=True) #self.timeSeries.set_xlim(matplotlib.dates.date2num([self.seriesPlotInfo.currentStart, self.seriesPlotInfo.currentEnd])) #self.timeSeries.axis[:].set_major_formatter(FormatStrFormatter('%.2f')) self.timeSeries.axis[:].major_ticks.set_tick_out(True) self.timeSeries.axis["bottom"].label.set_pad(20) self.timeSeries.axis["bottom"].major_ticklabels.set_pad(15) self.timeSeries.axis["bottom"].major_ticklabels.set_rotation(15) self.timeSeries.axis[:].major_ticklabels.set_picker(True) plt.gcf().autofmt_xdate() #self.figure.tight_layout() if not self.toolbar._views.empty(): for v in self.toolbar._views: del(v) self.toolbar.push_current() self.canvas.draw() def updateCursor(self, selectedObject=None, deselectedObject=None): """ :param selectedObject: """ try: if selectedObject: """ Activate Cursor. Happens when a plot is selected """ if self.seriesPlotInfo: seriesInfo = self.seriesPlotInfo.getSeries(selectedObject.id) if seriesInfo: currentAxis = None # If there a key with the axisTitle we are interested in, set currentaxis to that. if seriesInfo.axisTitle in self.axislist.keys(): currentAxis = self.axislist[seriesInfo.axisTitle] # If nothing is in the axislist, we don't care about it elif len(self.axislist) < 1: currentAxis = None self.configureCursor(currentAxis=currentAxis) else:#elif deselectedObject: """ Deactivate Cursor. This happens when the plot is deselected """ self.deactivateCursor(deselectedObject) except AttributeError as e: message= "Ignoring Attribute Error", e print message logger.error (message) def deactivateCursor(self, deselectedObject=None): # Remove an object if supplied if deselectedObject: for i in self.cursors: if i.selected == deselectedObject: i.disable() break # Disable existing Cursors elif self.cursors: for i in self.cursors: i.disable() def configureCursor(self, currentAxis=None): """Creates the cursors for each axes in order to provide data hovering""" self.deactivateCursor() self.cursors = [] # initialize cursors for axes from currently selected axes for k, v in self.axislist.iteritems(): i = Cursor(self.canvas, self.toolbar, v, k) ## If I have selected an axis that is in the axislist if v == currentAxis: i.enable() i.setSelected(currentAxis) # If there is only one axis in the axislist, default to the first axis elif len(self.axislist) == 1: i.enable() i.setSelected(self.axislist.values()[0]) # Else I disable the other axes that I don't care about else: i.setSelected(None) i.disable() self.cursors.append(i) def setTimeSeriesTitle(self, title=""): """Set the title of the TimeSeries plot""" self.timeSeries.set_title(title, picker=True) def setEdit(self, id): self.editseriesID = id self.alpha = .5 if self.seriesPlotInfo and self.seriesPlotInfo.isPlotted(self.editseriesID): self.editCurve = self.seriesPlotInfo.getSeries(self.editseriesID) ## TODO Duplicate UpdatePlot? logger.debug("Called duplicate updateplot") self.updatePlot() def make_patch_spines_invisible(self, ax): ax.set_frame_on(True) ax.patch.set_visible(False) for sp in ax.spines.itervalues(): sp.set_visible(False) def _onMotion(self, event): """ :type event: matplotlib.backend_bases.MouseEvent :return: """ try: if event.xdata and event.ydata: xValue = matplotlib.dates.num2date(event.xdata).replace(tzinfo=None) #self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%Y-%m-%d %H:%M:%S"), event.ydata)) #self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%b %d, %Y %H:%M:%S"), event.ydata)) self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%b %d, %Y %H:%M"), event.ydata)) self.toolbar.msg.SetForegroundColour((66, 66, 66)) else: self.toolbar.msg.SetLabelText("") except ValueError : pass def _onPick(self, event): """ :param event: :return: """ if isinstance(event.artist, Line2D): thisline = event.artist xdata = thisline.get_xdata() ydata = thisline.get_ydata() ind = event.ind xValue = xdata[ind][0] yValue = ydata[ind][0] #tip = '(%s, %s)' % (xValue.strftime("%Y-%m-%d %H:%M:%S"), yValue) #tip = '(%s, %s)' % (xValue.strftime("%b %d, %Y %H:%M:%S"), yValue) tip = '(%s, %s)' % (xValue.strftime("%b %d, %Y %H:%M"), yValue) self.tooltip.SetTip(tip) self.tooltip.Enable(True) self.tooltip.SetAutoPop(10000) elif isinstance(event.artist, Text): text = event.artist #print "Picking Label: ", text.get_text() def _onFigureLeave(self, event): """Catches mouse leaving the figure :param event: :return: """ if self.tooltip.Window.Enabled: self.tooltip.SetTip("")
class plotTimeSeries(wx.Panel): def __init__(self, parent, id, pos, size, style, name): self._init_ctrls(parent) def _init_coll_boxSizer1_Items(self, parent): # generated method, don't edit parent.AddWindow(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) parent.AddWindow(self.toolbar, 0, wx.EXPAND) def _init_ctrls(self, parent): wx.Panel.__init__(self, parent, -1) self.parent = parent #init Plot figure = plt.figure() self.timeSeries = host_subplot( 111, axes_class=AA.Axes) self.init_plot(figure) #self.hoverAction = self.canvas.mpl_connect('motion_notify_event', self._onMotion) #self.pointPick = self.canvas.mpl_connect('pick_event', self._onPick) self.canvas.mpl_connect('figure_leave_event', self._onFigureLeave) Publisher.subscribe(self.updateCursor, "updateCursor") # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, allowselect=True) self.toolbar.Realize() self.seriesPlotInfo = None #set properties self.fontP = FontProperties() self.fontP.set_size('x-small') self.format = '-o' self.alpha=1 self._setColor("WHITE") left = 0.125 # the left side of the subplots of the figure right = 0.9 # the right side of the subplots of the figure bottom = 0.51 # the bottom of the subplots of the figure top = 1.2 # the top of the subplots of the figure wspace = .8 # the amount of width reserved for blank space between subplots hspace = .8 # the amount of height reserved for white space between subplots plt.subplots_adjust( left=left, bottom=bottom, right=right, top=top, wspace=wspace, hspace=hspace ) plt.tight_layout() #init hover tooltip # create a long tooltip with newline to get around wx bug (in v2.6.3.3) # where newlines aren't recognized on subsequent self.tooltip.SetTip() calls self.tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n') self.canvas.SetToolTip(self.tooltip) self.tooltip.Enable(False) self.tooltip.SetDelay(0) #init lists #self.lines = {} self.lines = [] self.axislist = {} self.curveindex = -1 self.editseriesID = -1 self.editCurve = None self.editPoint =None self.hoverAction = None self.selplot= None self.cursors = [] self.canvas.draw() self._init_sizers() def _init_sizers(self): # generated method, don't edit self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL) self._init_coll_boxSizer1_Items(self.boxSizer1) self.SetSizer(self.boxSizer1) def init_plot(self, figure): self.timeSeries.plot([], [], picker=5) self.setTimeSeriesTitle("No Data to Plot") self.canvas = FigCanvas(self, -1, figure) self.canvas.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.isShowLegendEnabled = False ''' def changePlotSelection(self, datetime_list=[]): cc= ColorConverter() # k black, # r red # needs to have graph first selected = cc.to_rgba('r', 1) unselected = cc.to_rgba('k', 0.1) allunselected = cc.to_rgba('k', 1) if self.editPoint: colorlist=[allunselected] *len(self.editCurve.dataTable) if len(datetime_list)>0: for i in xrange(len(self.editCurve.dataTable)): if self.editCurve.dataTable[i][1] in datetime_list: colorlist[i]=selected else: colorlist[i]=unselected self.editPoint.set_color(colorlist) #self.editPoint.set_color(['k' if x == 0 else 'r' for x in tflist]) self.canvas.draw() ''' ## TODO 10/15/2014 Change function so that it will accept a list of datavalues. This will remove the need to loop through the values currently plotted and we would instead plot the list of datetimes and datavalues together. def changePlotSelection(self, datetime_list=[], datavalues=[]): #for entire list of points if selected add to new lists newx= [] newy=[] if self.selplot: self.selplot.remove() del(self.selplot) self.selplot = None if len( datetime_list) >0: for x, y, a, b, c in self.editCurve.dataTable: if y in datetime_list: newx.append(x) newy.append(y) self.selplot = self.axislist[self.editSeries.axisTitle].scatter( newy, newx, s=35, c='red', edgecolors='none', zorder=12, marker='s', alpha=1) self.canvas.draw() def changeSelection(self, datetime_list=[]): self.changePlotSelection( datetime_list) self.parent.record_service.select_points(datetime_list=datetime_list) Publisher.sendMessage(("changeTableSelection"), datetime_list= datetime_list) def onShowLegend(self, isVisible): if isVisible: self.isShowLegendEnabled = True plt.subplots_adjust(bottom=.1 + .1) leg = self.timeSeries.legend(loc='upper right', ncol=2, fancybox=True, prop=self.fontP) leg.get_frame().set_alpha(.5) leg.draggable(state=True) else: self.isShowLegendEnabled = False plt.subplots_adjust(bottom=.1) self.timeSeries.legend_ = None plt.gcf().autofmt_xdate() self.canvas.draw() def onPlotType(self, ptype): # self.timeSeries.clear() if ptype == "line": ls = '-' m = 'None' elif ptype == "point": ls = 'None' m = 'o' else: ls = '-' m = 'o' self.format = ls + m for line, i in zip(self.lines, range(len(self.lines))): if not (i == self.curveindex): plt.setp(line, linestyle=ls, marker=m) if self.isShowLegendEnabled : self.onShowLegend(self.isShowLegendEnabled) plt.gcf().autofmt_xdate() self.canvas.draw() #clear plot def clear(self): lines = [] for key, ax in self.axislist.items(): ax.clear() self.axislist = {} # self.stopEdit() #print "TimeSeries: ", dir(self.timeSeries), type(self.timeSeries) #plt.cla() #plt.clf() self.timeSeries.plot([], [], picker=5) def stopEdit(self): self.clear() self.selectedlist = None self.selplot = None self.lman = None #self.canvas.mpl_disconnect(self.hoverAction) try: self.canvas.mpl_disconnect(self.pointPick) self.pointPick = None except AttributeError as e: logger.error(e) self.hoverAction = None self.xys = None self.alpha=1 self.curveindex = -1 self.editCurve = None # self.RefreshPlot() if self.seriesPlotInfo and self.seriesPlotInfo.isPlotted(self.editseriesID): self.updatePlot() self.toolbar.stopEdit() self.editseriesID = -1 def updateValues(self): # self.addEdit(self.editCursor, self.editSeries, self.editDataFilter) #clear current edit points and curve if self.editCurve: curraxis = self.axislist[self.editCurve.axisTitle] for l in curraxis.lines: if l.get_label() == self.editCurve.plotTitle: curraxis.lines.remove(l) #redraw editpoints and curve self.seriesPlotInfo.updateEditSeries() self.editCurve = self.seriesPlotInfo.getEditSeriesInfo() self.drawEditPlot(self.editCurve) self.canvas.draw() Publisher.sendMessage("refreshTable", e=None) # self.parent.parent.dataTable.Refresh() plt.gcf().autofmt_xdate() self.canvas.draw() def drawEditPlot(self, oneSeries): self.editSeries = oneSeries self.axislist[self.editSeries.axisTitle].set_zorder(10) self.lines[self.curveindex] = self.axislist[self.editSeries.axisTitle].\ plot_date([x[1] for x in oneSeries.dataTable], [x[0] for x in oneSeries.dataTable], "-s", color=oneSeries.color, xdate=True, tz=None, label=oneSeries.plotTitle, zorder=10, alpha=1, picker=5.0, pickradius=5.0, markersize=4.5) #self.selectedlist = self.parent.record_service.get_filter_list() '''self.editPoint = self.axislist[self.editSeries.axisTitle].\ scatter([x[1] for x in oneSeries.dataTable], [x[0] for x in oneSeries.dataTable], s=35, c='k', edgecolors='none', zorder=11, marker='s', alpha=1)# >, <, v, ^,s ''' self.xys = [(matplotlib.dates.date2num(x[1]), x[0]) for x in oneSeries.dataTable] self.toolbar.editSeries(self.xys, self.editCurve) self.timeradius = self.editCurve.timeRadius self.pointPick = self.canvas.mpl_connect('pick_event', self._onPick) def _setColor(self, color): """Set figure and canvas colours to be the same. :rtype : object """ plt.gcf().set_facecolor(color) plt.gcf().set_edgecolor(color) self.canvas.SetBackgroundColour(color) def close(self): #plt.clf() #plt.close() pass def Plot(self, seriesPlotInfo): self.seriesPlotInfo = seriesPlotInfo self.updatePlot() # resets the home view - will remove any previous zooming self.toolbar.update() self.toolbar.push_current() #self._views.home() #self._positions.home() #self.set_history_buttons() def updatePlot(self): self.clear() count = self.seriesPlotInfo.count() self.setUpYAxis() self.lines = [] for oneSeries in self.seriesPlotInfo.getAllSeries(): #is this the series to be edited if oneSeries.seriesID == self.seriesPlotInfo.getEditSeriesID(): self.curveindex = len(self.lines) self.lines.append("") self.editCurve = oneSeries self.drawEditPlot(oneSeries) else: if oneSeries.dataTable is not None: curraxis = self.axislist[oneSeries.axisTitle] curraxis.set_zorder(1) self.lines.append( curraxis.plot_date( [x[1] for x in oneSeries.dataTable], [x[0] for x in oneSeries.dataTable], self.format, color=oneSeries.color, xdate=True, tz=None, antialiased=True, label=oneSeries.plotTitle, alpha=self.alpha, picker=5.0, pickradius=5.0, markersize=4 ) ) if count > 1: self.setTimeSeriesTitle("") plt.subplots_adjust(bottom=.1 + .1) # self.timeSeries.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), # ncol=2, prop = self.fontP) self.timeSeries.legend(loc='upper center', bbox_to_anchor=(0.5, -1.75), ncol=2, prop=self.fontP) elif count == 0: self.setTimeSeriesTitle("") self.timeSeries.legend_ = None else: self.setTimeSeriesTitle(oneSeries.siteName) plt.subplots_adjust(bottom=.1) self.timeSeries.legend_ = None self.timeSeries.set_xlabel("Date", picker=True) #self.timeSeries.set_xlim(matplotlib.dates.date2num([self.seriesPlotInfo.currentStart, self.seriesPlotInfo.currentEnd])) #self.timeSeries.axis[:].set_major_formatter(FormatStrFormatter('%.2f')) self.timeSeries.axis[:].major_ticks.set_tick_out(True) self.timeSeries.axis["bottom"].label.set_pad(20) self.timeSeries.axis["bottom"].major_ticklabels.set_pad(15) self.timeSeries.axis["bottom"].major_ticklabels.set_rotation(15) self.timeSeries.axis[:].major_ticklabels.set_picker(True) plt.gcf().autofmt_xdate() plt.tight_layout() if not self.toolbar._views.empty(): for v in self.toolbar._views: del(v) self.toolbar.push_current() self.canvas.draw() def updateCursor(self, selectedObject): """ :param selectedObject: """ try: if selectedObject: if self.seriesPlotInfo: seriesInfo = self.seriesPlotInfo.getSelectedSeries(selectedObject.id) if seriesInfo: currentAxis = None # If there a key with the axisTitle we are interested in, set currentaxis to that. if seriesInfo.axisTitle in self.axislist.keys(): currentAxis = self.axislist[seriesInfo.axisTitle] # If nothing is in the axislist, we don't care about it elif len(self.axislist) < 1: currentAxis = None self.configureCursor(currentAxis) except AttributeError as e: print "Ignoring Attribute Error", e def configureCursor(self, currentAxis=None): """Creates the cursors for each axes in order to provide data hovering""" # Disable existing Cursors if self.cursors: for i in self.cursors: i.disable() self.cursors = [] # initialize cursors for axes from currently selected axes for k, v in self.axislist.iteritems(): i = Cursor(self.canvas, self.toolbar, v, k) ## If I have selected an axis that is in the axislist if v == currentAxis: i.enable() i.setSelected(currentAxis) # If there is only one axis in the axislist, default to the first axis elif len(self.axislist) == 1: i.enable() i.setSelected(self.axislist.values()[0]) # Else I disable the other axes that I don't care about else: i.setSelected(None) i.disable() self.cursors.append(i) def setTimeSeriesTitle(self, title=""): """Set the title of the TimeSeries plot""" self.timeSeries.set_title(title, picker=True) def setEdit(self, id): self.editseriesID = id self.alpha = .5 if self.seriesPlotInfo and self.seriesPlotInfo.isPlotted(self.editseriesID): self.editCurve = self.seriesPlotInfo.getSeries(self.editseriesID) ## TODO Duplicate UpdatePlot? logger.debug("Called duplicate updateplot") self.updatePlot() def setUpYAxis(self): self.axislist = {} left = 0 right = 0 adj = .05 editaxis = None #loop through the list of curves and add an axis for each for oneSeries in self.seriesPlotInfo.getAllSeries(): #test to see if the axis already exists if oneSeries.edit: editaxis = oneSeries.axisTitle if not oneSeries.axisTitle in self.axislist: self.axislist[oneSeries.axisTitle] = None keys = self.axislist.keys() if editaxis: for i in range(len(keys)): if keys[i] == editaxis: keys.pop(i) break keys.insert(0, editaxis) leftadjust = -30 for i, axis in zip(range(len(self.axislist)), keys): if i % 2 == 0: left = left + 1 #add to the left(yaxis) if i == 0: #if first plot use the orig axis newAxis = self.timeSeries else: newAxis = self.timeSeries.twinx() new_fixed_axis = newAxis.get_grid_helper().new_fixed_axis newAxis.axis['left'] = new_fixed_axis(loc='left', axes=newAxis, offset=(leftadjust * left, 0)) newAxis.axis["left"].toggle(all=True) newAxis.axis["right"].toggle(all=False) leftadjust -= 15 else: right = right + 1 #add to the right(y2axis) newAxis = self.timeSeries.twinx() new_fixed_axis = newAxis.get_grid_helper().new_fixed_axis newAxis.axis['right'] = new_fixed_axis(loc='right', axes=newAxis, offset=(60 * (right - 1), 0)) newAxis.axis['right'].toggle(all=True) a = newAxis.set_ylabel(axis, picker=True) a.set_picker(True) #logger.debug("axis label: %s" % (axis)) self.axislist[axis] = newAxis def _onMotion(self, event): """ :type event: matplotlib.backend_bases.MouseEvent :return: """ try: if event.xdata and event.ydata: xValue = matplotlib.dates.num2date(event.xdata).replace(tzinfo=None) #self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%Y-%m-%d %H:%M:%S"), event.ydata)) #self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%b %d, %Y %H:%M:%S"), event.ydata)) self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%b %d, %Y %H:%M"), event.ydata)) self.toolbar.msg.SetForegroundColour((66, 66, 66)) else: self.toolbar.msg.SetLabelText("") except ValueError: pass def _onPick(self, event): """ :param event: :return: """ if isinstance(event.artist, Line2D): thisline = event.artist xdata = thisline.get_xdata() ydata = thisline.get_ydata() ind = event.ind xValue = xdata[ind][0] yValue = ydata[ind][0] #tip = '(%s, %s)' % (xValue.strftime("%Y-%m-%d %H:%M:%S"), yValue) #tip = '(%s, %s)' % (xValue.strftime("%b %d, %Y %H:%M:%S"), yValue) tip = '(%s, %s)' % (xValue.strftime("%b %d, %Y %H:%M"), yValue) self.tooltip.SetTip(tip) self.tooltip.Enable(True) self.tooltip.SetAutoPop(10000) elif isinstance(event.artist, Text): text = event.artist #print "Picking Label: ", text.get_text() def _onFigureLeave(self, event): """Catches mouse leaving the figure :param event: :return: """ if self.tooltip.Window.Enabled: self.tooltip.SetTip("")
class plotProb(wx.Panel): def _init_coll_boxSizer1_Items(self, parent): # generated method, don't edit parent.AddWindow(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) parent.AddWindow(self.toolbar, 0, wx.EXPAND) def _init_sizers(self): # generated method, don't edit self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL) self._init_coll_boxSizer1_Items(self.boxSizer1) self.SetSizer(self.boxSizer1) def Clear(self): self.plot.clear() def _init_ctrls(self, prnt): #matplotlib.figure.Figure.__init__(self) wx.Panel.__init__(self, prnt, -1) self.figure = matplotlib.figure.Figure() self.plot = self.figure.add_subplot(111) self.plot.axis([0, 1, 0, 1]) # self.plot.plot([], []) self.plot.set_title("No Data To Plot") self.canvas = FigCanvas(self, -1, self.figure) # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas) self.toolbar.Realize() #self.canvas.SetCursor(wx.StockCursor(wx.CURSOR_CROSS)) #self.canvas.SetScrollbar(wx.HORIZONTAL, 0,5, 1000) self.SetColor("WHITE") self.canvas.SetFont( wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.fontP = FontProperties() self.fontP.set_size('small') self.canvas.draw() self._init_sizers() def OnPlotType(self, ptype): # self.timeSeries.clear() if ptype == "line": ls = '-' m = 'None' elif ptype == "point": ls = 'None' m = 's' else: ls = '-' m = 's' # print plt.setp(self.lines) # print(len(self.lines)) format = ls + m for line in self.lines: plt.setp(line, linestyle=ls, marker=m) self.canvas.draw() def OnShowLegend(self, isVisible): # print self.timeSeries.show_legend if isVisible: plt.subplots_adjust(bottom=.1 + .1) self.plot.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), ncol=2, prop=self.fontP) else: plt.subplots_adjust(bottom=.1) self.plot.legend_ = None # self.timeSeries.plot(legend= not isVisible) self.canvas.draw() def Plot(self, seriesPlotInfo): self.seriesPlotInfo = seriesPlotInfo self.updatePlot() def updatePlot(self): self.Clear() count = self.seriesPlotInfo.count() self.lines = [] self.plot = self.figure.add_subplot(111) for oneSeries in self.seriesPlotInfo.GetSeriesInfo(): self.plot.set_xlabel("Cumulative Frequency < Stated Value %") if count > 1: self.plot.set_ylabel("\n".join( textwrap.wrap(oneSeries.axisTitle, 50))) self.plot.set_title("") else: self.plot.set_ylabel("\n".join( textwrap.wrap(oneSeries.axisTitle, 50))) self.plot.set_title("\n".join( textwrap.wrap(oneSeries.plotTitle, 55))) self.lines.append( self.plot.plot(oneSeries.Probability.Xaxis, oneSeries.Probability.Yaxis, 'bs', color=oneSeries.color, label=oneSeries.plotTitle)) self.setXaxis() if count > 1: plt.subplots_adjust(bottom=.1 + .1) self.plot.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), ncol=2, prop=self.fontP) else: plt.subplots_adjust(bottom=.1) self.plot.legend_ = None self.canvas.draw() def addPlot(self, cursor, series, Filter): # self.cursor = Values[0] self.cursor = cursor self.cursor.execute("SELECT DataValue FROM DataValues" + Filter) self.dataValues = [x[0] for x in self.cursor.fetchall()] # self.Series= Values[1] self.Series = series self.plot.clear() length = len(self.dataValues) self.Yaxis = sorted(self.dataValues) self.Xaxis = [] for it in range(0, length): #curValue = datavalues[it] curFreq = self.CalcualteProbabilityFreq(it + 1, length) curX = self.CalculateProbabilityXPosition(curFreq) #self.Yaxis.append(curValue) self.Xaxis.append(curX) #print self.Xaxis # print self.Yaxis self.plot.clear() x = range(len(self.Xaxis)) self.plot.set_xlabel("Cumulative Frequency < Stated Value %") self.plot.set_ylabel("\n".join( textwrap.wrap( self.Series.variable_name + "(" + self.Series.variable_units_name + ")", 50))) self.plot.set_title("\n".join( textwrap.wrap( self.Series.site_name + " " + self.Series.variable_name, 55))) self.plot = self.figure.add_subplot(111) self.lines = self.plot.plot(self.Xaxis, self.Yaxis, 'bs') self.setXaxis() self.canvas.draw() def setXaxis(self): self.plot.set_xticklabels([ "0.01", "0.02", "0.02", "1", "2", "5", "10", "20", "30", "40", "50", "60", "70", "80", "90", "95", "98", "99", "99.9", "99.98", "99.99" ]) self.plot.set_xticks([ -3.892, -3.5, -3.095, -2.323, -2.055, -1.645, -1.282, -0.842, -0.542, -0.254, 0, 0.254, 0.542, 0.842, 1.282, 1.645, 2.055, 2.323, 3.095, 3.5, 3.892 ]) self.plot.set_xbound(-4, 4) def SetColor(self, color): """Set figure and canvas colours to be the same.""" self.figure.set_facecolor(color) self.figure.set_edgecolor(color) self.canvas.SetBackgroundColour(color) def CalculateProbabilityXPosition(self, freq): try: return round(4.91 * ((freq**.14) - (1.00 - freq)**.14), 3) except: print "An error occurred while calculating the X-Position for a point in the prob plot" pass def CalcualteProbabilityFreq(self, rank, numRows): try: return round((rank - .0375) / (numRows + 1 - (2 * 0.375)), 3) except: print "An error occured while calculating the frequency for a point in the prob plot" pass def __init__(self, parent, id, pos, size, style, name): self._init_ctrls(parent)
def _init_ctrls(self, parent): wx.Panel.__init__(self, parent, -1) self.parent = parent #init Plot figure = plt.figure() self.timeSeries = host_subplot( 111, axes_class=AA.Axes) self.init_plot(figure) #self.hoverAction = self.canvas.mpl_connect('motion_notify_event', self._onMotion) #self.pointPick = self.canvas.mpl_connect('pick_event', self._onPick) self.canvas.mpl_connect('figure_leave_event', self._onFigureLeave) Publisher.subscribe(self.updateCursor, "updateCursor") # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, allowselect=True) self.toolbar.Realize() self.seriesPlotInfo = None #set properties self.fontP = FontProperties() self.fontP.set_size('x-small') self.format = '-o' self.alpha=1 self._setColor("WHITE") left = 0.125 # the left side of the subplots of the figure right = 0.9 # the right side of the subplots of the figure bottom = 0.51 # the bottom of the subplots of the figure top = 1.2 # the top of the subplots of the figure wspace = .8 # the amount of width reserved for blank space between subplots hspace = .8 # the amount of height reserved for white space between subplots plt.subplots_adjust( left=left, bottom=bottom, right=right, top=top, wspace=wspace, hspace=hspace ) plt.tight_layout() #init hover tooltip # create a long tooltip with newline to get around wx bug (in v2.6.3.3) # where newlines aren't recognized on subsequent self.tooltip.SetTip() calls self.tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n') self.canvas.SetToolTip(self.tooltip) self.tooltip.Enable(False) self.tooltip.SetDelay(0) #init lists #self.lines = {} self.lines = [] self.axislist = {} self.curveindex = -1 self.editseriesID = -1 self.editCurve = None self.editPoint =None self.hoverAction = None self.selplot= None self.cursors = [] self.canvas.draw() self._init_sizers()
class PlotBox(wx.Panel): def _init_coll_boxSizer1_Items(self, parent): # generated method, don't edit parent.AddWindow(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) parent.AddWindow(self.toolbar, 0, wx.EXPAND) def _init_sizers(self): # generated method, don't edit self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL) self._init_coll_boxSizer1_Items(self.boxSizer1) self.SetSizer(self.boxSizer1) def _init_ctrls(self, prnt): # matplotlib.figure.Figure.__init__(self) wx.Panel.__init__(self, prnt, -1) Publisher.subscribe(self.monthly, ("box.Monthly")) Publisher.subscribe(self.yearly, ("box.Yearly")) Publisher.subscribe(self.seasonaly, ("box.Seasonal")) Publisher.subscribe(self.overall, ("box.Overall")) self.figure = Figure() # self.figure = plt.figure() plot = self.figure.add_subplot(111) #self.plot.axis([0, 1, 0, 1]) # plot.set_title("No Data To Plot") self.canvas = FigCanvas(self, -1, self.figure) # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, True) self.toolbar.Realize() self.figure.tight_layout() self.setColor("WHITE") self.canvas.SetFont( wx.Font(15, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.canvas.draw() self._init_sizers() def clear(self): self.figure.clear() def close(self): self.figure.clf() # plt.close('all') def gridSize(self, cells): rows = 1 cols = 1 while rows * cols < cells: if rows == cols: cols = cols + 1 else: rows = rows + 1 return rows, cols def textSize(self, cells): wrap = 40 wrap = wrap - (cells * 3) text = 20 - cells return wrap, text def Plot(self, seriesPlotInfo): self.seriesPlotInfo = seriesPlotInfo self.updatePlot() def updatePlot(self): self.clear() rows, cols = self.gridSize(self.seriesPlotInfo.count()) # self.figure, self.axes = plt.subplots(nrows=rows, ncols=cols) i = 1 for oneSeries in self.seriesPlotInfo.getAllSeries(): if len(oneSeries.dataTable) > 0: self._createPlot(oneSeries, rows, cols, i) i += 1 # self.figure.tight_layout() self.canvas.draw() def _createPlot(self, oneSeries, rows, cols, index): ax = self.figure.add_subplot(repr(rows) + repr(cols) + repr(index)) med = oneSeries.BoxWhisker.currinterval.medians ci = oneSeries.BoxWhisker.currinterval.confint mean = oneSeries.BoxWhisker.currinterval.means cl = oneSeries.BoxWhisker.currinterval.conflimit # Plot Means confidence level for x in range(len(mean)): ax.vlines(x + 1, cl[x][0], cl[x][1], color='r', linestyle="solid") # Plot Mean ax.scatter([range(1, len(mean) + 1)], mean, marker='o', c='r', s=10) # Plot Median ax.scatter([range(1, len(med) + 1)], med, marker='s', c="k", s=10) # bp = onSeries.dataTable.boxplot( bp = oneSeries.dataTable[ oneSeries.dataTable["DataValue"] != oneSeries.noDataValue].boxplot( column="DataValue", ax=ax, by=oneSeries.BoxWhisker.currinterval.groupby, rot=35, notch=True, sym="-s", conf_intervals=ci, return_type='dict', grid=False) # Set Colors of the Box Whisker plot try: plt.setp(bp['DataValue']['whiskers'], color='k', linestyle='-') plt.setp(bp['DataValue']['medians'], color='k', linestyle='-') plt.setp(bp['DataValue']['boxes'], color='GREY', linestyle='-') plt.setp(bp['DataValue']['caps'], color='k') plt.setp(bp['DataValue']['fliers'], markersize=3.5, color=oneSeries.color) except: plt.setp(bp['whiskers'], color='k', linestyle='-') plt.setp(bp['medians'], color='k', linestyle='-') plt.setp(bp['boxes'], color='GREY', linestyle='-') plt.setp(bp['caps'], color='k') plt.setp(bp['fliers'], markersize=3.5, color=oneSeries.color) #Labels ax.set_xticklabels( [x for x in oneSeries.BoxWhisker.currinterval.xlabels]) # set the text of the first few minor ticks created by pandas.plot # remove the minor xtick labels set by pandas.plot ax.set_xticklabels([], minor=True) # turn the minor ticks created by pandas.plot off # plt.minorticks_off() wrap, text = self.textSize(self.seriesPlotInfo.count()) self.canvas.SetFont( wx.Font(text, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) ax.set_xlabel("\n".join( textwrap.wrap(oneSeries.BoxWhisker.currinterval.title, wrap))) ax.set_ylabel("\n".join( textwrap.wrap( oneSeries.variableName + "\n (" + oneSeries.variableUnits + ")", wrap))) self.figure.suptitle("") ax.set_title("\n".join(textwrap.wrap(oneSeries.siteName, wrap))) def setColor(self, color): # """Set figure and canvas colours to be the same.""" self.figure.set_facecolor(color) self.figure.set_edgecolor(color) self.canvas.SetBackgroundColour(color) def monthly(self, str): # print "monthly" self.seriesPlotInfo.setBoxInterval("Month") self.updatePlot() def seasonaly(self, str): # print"seasonal" self.seriesPlotInfo.setBoxInterval("Season") self.updatePlot() def yearly(self, str): # print "yearly" self.seriesPlotInfo.setBoxInterval("Year") self.updatePlot() def overall(self, str): # print "overall" self.seriesPlotInfo.setBoxInterval("Overall") self.updatePlot() def __init__(self, parent, id, pos, size, style, name): self._init_ctrls(parent)
class plotHist(wx.Panel): def _init_coll_boxSizer1_Items(self, parent): # generated method, don't edit parent.AddWindow(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) parent.AddWindow(self.toolbar, 0, wx.EXPAND) def _init_sizers(self): # generated method, don't edit self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL) self._init_coll_boxSizer1_Items(self.boxSizer1) self.SetSizer(self.boxSizer1) def _init_ctrls(self, prnt): # matplotlib.figure.Figure.__init__(self) wx.Panel.__init__(self, prnt, -1) self.figure = Figure() plot = self.figure.add_subplot(111) plot.set_title("No Data To Plot") self.canvas = FigCanvas(self, -1, self.figure) # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, True) self.toolbar.Realize() self.figure.tight_layout() self.setColor("WHITE") self.canvas.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.canvas.draw() self._init_sizers() self.bins = 50 def changeNumOfBins(self, bins): self.bins = bins self.updatePlot() def clear(self): self.figure.clear() # plt.clear() def gridSize(self, cells): rows = 1 cols = 1 while rows * cols < cells: if rows == cols: cols = cols + 1 else: rows = rows + 1 return rows, cols def textSize(self, cells): wrap = 50 wrap = wrap - (cells * 3) text = 20 - cells return wrap, text def Plot(self, seriesPlotInfo): self.seriesPlotInfo = seriesPlotInfo self.updatePlot() def updatePlot(self): self.clear() rows, cols = self.gridSize(self.seriesPlotInfo.count()) logger.debug("Rows: %s, cols: %s" % (rows,cols)) i = 1 for oneSeries in self.seriesPlotInfo.getAllSeries(): if len(oneSeries.dataTable) > 0: self._createPlot(oneSeries, rows, cols, i) i += 1 #self.figure.tight_layout() self.canvas.draw() def _createPlot(self, oneSeries, rows, cols, index): ax = self.figure.add_subplot(repr(rows) + repr(cols) + repr(index)) logger.debug("HISTOGRAM: %s"% ax) # oneSeries.filteredData.hist(ax= ax, color='k', alpha=0.5, bins=50) his = oneSeries.dataTable.hist(column="DataValue", ax=ax, bins=self.bins, facecolor=oneSeries.color, label=oneSeries.siteName + " " + oneSeries.variableName, grid=False) wrap, text = self.textSize(self.seriesPlotInfo.count()) ax.set_xlabel("\n".join(textwrap.wrap(oneSeries.variableName, wrap))) ax.set_ylabel("Number of Observations") self.canvas.SetFont(wx.Font(text, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) ax.set_title("\n".join(textwrap.wrap(oneSeries.siteName, wrap))) def setColor(self, color): """Set figure and canvas colours to be the same.""" self.figure.set_facecolor(color) self.figure.set_edgecolor(color) self.canvas.SetBackgroundColour(color) def __init__(self, parent, id, pos, size, style, name): self._init_ctrls(parent)
class plotTimeSeries(wx.Panel): def _init_coll_boxSizer1_Items(self, parent): # generated method, don't edit parent.AddWindow(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) parent.AddWindow(self.toolbar, 0, wx.EXPAND) def _init_sizers(self): # generated method, don't edit self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL) self._init_coll_boxSizer1_Items(self.boxSizer1) self.SetSizer(self.boxSizer1) def _init_ctrls(self, parent): #matplotlib.figure.Figure.__init__(self) wx.Panel.__init__(self, parent, -1) self.parent = parent # self.figure = Figure()#matplotlib.figure.Figure() #init Plot # self.timeSeries=self.figure.add_subplot(111) self.timeSeries = host_subplot(111, axes_class=AA.Axes) # self.timeSeries.axis([0, 1, 0, 1])# self.timeSeries.plot([],[]) self.timeSeries.set_title("No Data To Plot") self.canvas = FigCanvas(self, -1, plt.gcf()) # self.canvas = FigCanvas(self, -1, self.figure) self.canvas.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) # self.canvas.mpl_connect('pick_event', self.on_pick) # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, allowselect=True) self.toolbar.Realize() self.seriesPlotInfo= None self.fontP = FontProperties() self.fontP.set_size('small') self.format = '-o' self.SetColor("WHITE") #self.canvas.gca().xaxis.set_major_locator() #init lists self.lines=[] self.axislist={} self.curveindex = -1 self.editseriesID = -1 self.editCurve =None self.cid=None self.canvas.draw() self._init_sizers() # def changeSelectionDT(self, sellist): # #list of DateTimes # print sellist # self.parent.record_service.select_points(datetime_list= sellist) # sellist = self.selFormat(sellist) # self.changeSelection(sellist) # print sellist # def selFormat(self, pairs): # #convert selectionlist from datetimes to true false # print len(pairs) # if len(pairs) ==0: # return [False] * len(self.editData.DataValues) # verts =[ (matplotlib.dates.date2num(x), y) for x,y in pairs] # p = path.Path(verts) # ind = p.contains_points(self.xys) # return ind def changeSelection(self, sellist ): #list of True False self.editPoint.set_color(['k' if x==0 else 'r' for x in sellist]) self.parent.record_service.select_points_tf(sellist) Publisher.sendMessage(("changeTableSelection"), sellist=sellist) self.canvas.draw() def onDateChanged(self, date, time): # print date # self.timeSeries.clear() date = datetime.datetime(date.Year, date.Month+1, date.Day, 0, 0, 0) ## print date if time == "start": self.startDate = date else: self.endDate = date self.timeSeries.axis.axes.set_xbound(self.startDate, self.endDate) self.canvas.draw() def set_date_bound(self, start, end): if start < self.overallStart: self.overallStart = start if end > self.currEnd: self.currEnd = end def OnShowLegend(self, isVisible): # print self.timeSeries.show_legend if isVisible: plt.subplots_adjust(bottom=.1+.1) self.timeSeries.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), ncol=2, prop = self.fontP) else: plt.subplots_adjust(bottom=.1) self.timeSeries.legend_=None # self.timeSeries.plot(legend= not isVisible) self.canvas.draw() def OnPlotType(self, ptype): # self.timeSeries.clear() if ptype == "line": ls = '-' m='None' elif ptype == "point": ls='None' m='o' else: ls = '-' m='o' # print plt.setp(self.lines) # print(len(self.lines)) format = ls+m for line, i in zip(self.lines, range(len(self.lines))): if not (i == self.curveindex): plt.setp(line, linestyle = ls, marker = m) self.canvas.draw() def Clear(self): lines = [] for key, ax in self.axislist.items(): ax.clear() # self.stopEdit() def stopEdit(self): self.Clear() self.selectedlist = None self.editPoint =None self.lman= None self.canvas.mpl_disconnect(self.cid) self.cid=None self.xys = None self.curveindex = -1 self.editCurve =None # self.RefreshPlot() if self.seriesPlotInfo and self.seriesPlotInfo.IsPlotted(self.editseriesID): self.updatePlot() self.editseriesID = -1 def updateValues(self): # self.addEdit(self.editCursor, self.editSeries, self.editDataFilter) #clear current edit points and curve curraxis= self.axislist[self.editCurve.axisTitle] for l in curraxis.lines: if l.get_label() == self.editCurve.plotTitle: curraxis.lines.remove(l) self.editPoint.remove() #redraw editpoints and curve self.seriesPlotInfo.UpdateEditSeries() self.editCurve= self.seriesPlotInfo.GetEditSeriesInfo() self.drawEditPlot(self.editCurve) Publisher.sendMessage(("refreshTable"), e=None) # self.parent.parent.dataTable.Refresh() self.canvas.draw() def drawEditPlot(self, oneSeries): curraxis= self.axislist[oneSeries.axisTitle] self.lines[self.curveindex]=curraxis.plot_date([x[1] for x in oneSeries.dataTable], [x[0] for x in oneSeries.dataTable], "-", color=oneSeries.color, xdate = True, tz = None, label = oneSeries.plotTitle ) self.selectedlist = self.parent.record_service.get_filter_list() self.editPoint = curraxis.scatter([x[1] for x in oneSeries.dataTable], [x[0] for x in oneSeries.dataTable], s= 20, c=['k' if x==0 else 'r' for x in self.selectedlist]) self.xys = [(matplotlib.dates.date2num(x[1]), x[0]) for x in oneSeries.dataTable ] self.cid = self.canvas.mpl_connect('button_press_event', self.onpress) def SetColor( self, color): """Set figure and canvas colours to be the same.""" plt.gcf().set_facecolor( color ) plt.gcf().set_edgecolor( color ) self.canvas.SetBackgroundColour( color ) def Close(self): plt.close() def Plot(self, seriesPlotInfo): self.seriesPlotInfo= seriesPlotInfo self.updatePlot() def updatePlot(self): self.Clear() count = self.seriesPlotInfo.count() self.lines=[] # self.timeSeries=self.canvas.add_subplot(111) self.setUpYAxis() for oneSeries in self.seriesPlotInfo.GetSeriesInfo(): if oneSeries.seriesID == self.seriesPlotInfo.GetEditSeriesID(): self.curveindex = len(self.lines) self.lines.append("") self.editCurve= oneSeries self.drawEditPlot(oneSeries) else: curraxis= self.axislist[oneSeries.axisTitle] self.lines.append(curraxis.plot_date([x[1] for x in oneSeries.dataTable], [x[0] for x in oneSeries.dataTable], self.format, color=oneSeries.color, xdate = True, tz = None, label = oneSeries.plotTitle )) if count >1: # self.timeSeries.set_title("Multiple Series plotted") self.timeSeries.set_title("") plt.subplots_adjust(bottom=.1+.1) # self.timeSeries.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), # ncol=2, prop = self.fontP) self.timeSeries.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), ncol=2, prop = self.fontP) elif count == 0: self.timeSeries.set_title("") self.timeSeries.legend_=None else: self.timeSeries.set_title(oneSeries.plotTitle) plt.subplots_adjust(bottom=.1) self.timeSeries.legend_=None # self.timeSeries.set_xlim([0,1000]) self.timeSeries.set_xlabel("Date Time") self.canvas.draw() def setEdit(self, id): self.editseriesID = id if self.seriesPlotInfo and self.seriesPlotInfo.IsPlotted(self.editseriesID): self.editCurve = self.seriesPlotInfo.GetSeries(self.editseriesID) self.updatePlot() # print self.editCurve def setUpYAxis(self): self.axislist={} left = 0 right = 0 adj = .05 #loop through the list of curves and add an axis for each for oneSeries in self.seriesPlotInfo.GetSeriesInfo(): #test to see if the axis already exists if not oneSeries.axisTitle in self.axislist: self.axislist[oneSeries.axisTitle]=None for i, axis in zip(range(len(self.axislist)), self.axislist): if i %2==0: left = left+1 #add to the left(yaxis) if i==0: #if first plot use the orig axis newAxis =self.timeSeries else: newAxis= self.timeSeries.twinx() new_fixed_axis = newAxis.get_grid_helper().new_fixed_axis newAxis.axis['left']= new_fixed_axis(loc = 'left', axes= newAxis, offset= (-30*left ,0)) newAxis.axis["left"].toggle(all = True) newAxis.axis["right"].toggle(all = False) plt.subplots_adjust(left=.10+(adj*(left-1))) else: right= right+1 #add to the right(y2axis) newAxis= self.timeSeries.twinx() new_fixed_axis = newAxis.get_grid_helper().new_fixed_axis newAxis.axis['right']= new_fixed_axis(loc = 'right', axes= newAxis, offset= (60*(right-1) ,0)) newAxis.axis['right'].toggle(all=True) plt.subplots_adjust(right=.9-(adj*right)) newAxis.set_ylabel(axis) self.axislist[axis]=newAxis def callback(self, verts): seldatetimes= [matplotlib.dates.num2date(x[0]) for x in verts] #print seldatetimes # self.parent.record_service.select_points(datetime_list=seldatetimes) p = path.Path(verts) ind = p.contains_points(self.xys) self.changeSelection(ind) self.canvas.draw_idle() self.canvas.widgetlock.release(self.lasso) del self.lasso def onpress(self, event): if self.canvas.widgetlock.locked(): return if event.inaxes is None: return self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callback) # acquire a lock on the widget drawing self.canvas.widgetlock(self.lasso) def __init__(self, parent, id, pos, size, style, name): self._init_ctrls(parent)
def _init_ctrls(self, parent): wx.Panel.__init__(self, parent, -1) self.parent = parent #init Plot # matplotlib.figure.Figure self.figure = plt.figure() # matplotlib.axes.AxesSubplot self.timeSeries = host_subplot(111, axes_class=AA.Axes) self.setTimeSeriesTitle("No Data to Plot") # matplotlib.backends.backend_wxagg.FigureCanvasWxAgg self.canvas = FigCanvas(self, -1, self.figure) self.canvas.SetFont( wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.isShowLegendEnabled = False self.canvas.mpl_connect('figure_leave_event', self._onFigureLeave) Publisher.subscribe(self.updateCursor, "updateCursor") # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, allowselect=True) self.toolbar.Realize() self.seriesPlotInfo = None #set properties self.fontP = FontProperties() self.fontP.set_size('x-small') self.format = '-o' self.alpha = 1 self._setColor("WHITE") left = 0.125 # the left side of the subplots of the figure #right = 0.9 # the right side of the subplots of the figure #bottom = 0.51 # the bottom of the subplots of the figure #top = 1.2 # the top of the subplots of the figure #wspace = .8 # the amount of width reserved for blank space between subplots #hspace = .8 # the amount of height reserved for white space between subplots plt.subplots_adjust( left= left #, bottom=bottom, right=right, top=top, wspace=wspace, hspace=hspace ) plt.tight_layout() #init hover tooltip # create a long tooltip with newline to get around wx bug (in v2.6.3.3) # where newlines aren't recognized on subsequent self.tooltip.SetTip() calls self.tooltip = wx.ToolTip( tip='tip with a long %s line and a newline\n') self.canvas.SetToolTip(self.tooltip) self.tooltip.Enable(False) self.tooltip.SetDelay(0) #init lists #self.lines = {} self.lines = [] self.axislist = {} self.curveindex = -1 self.editseriesID = -1 self.editCurve = None self.editPoint = None self.hoverAction = None self.selplot = None self.cursors = [] self.canvas.draw() self._init_sizers()
class plotTimeSeries(wx.Panel): def __init__(self, parent, id, pos, size, style, name): self._init_ctrls(parent) def _init_coll_boxSizer1_Items(self, parent): # generated method, don't edit parent.AddWindow(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) parent.AddWindow(self.toolbar, 0, wx.EXPAND) def _init_ctrls(self, parent): wx.Panel.__init__(self, parent, -1) self.parent = parent #init Plot # matplotlib.figure.Figure self.figure = plt.figure() # matplotlib.axes.AxesSubplot self.timeSeries = host_subplot(111, axes_class=AA.Axes) self.setTimeSeriesTitle("No Data to Plot") # matplotlib.backends.backend_wxagg.FigureCanvasWxAgg self.canvas = FigCanvas(self, -1, self.figure) self.canvas.SetFont( wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.isShowLegendEnabled = False self.canvas.mpl_connect('figure_leave_event', self._onFigureLeave) Publisher.subscribe(self.updateCursor, "updateCursor") # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas, allowselect=True) self.toolbar.Realize() self.seriesPlotInfo = None #set properties self.fontP = FontProperties() self.fontP.set_size('x-small') self.format = '-o' self.alpha = 1 self._setColor("WHITE") left = 0.125 # the left side of the subplots of the figure #right = 0.9 # the right side of the subplots of the figure #bottom = 0.51 # the bottom of the subplots of the figure #top = 1.2 # the top of the subplots of the figure #wspace = .8 # the amount of width reserved for blank space between subplots #hspace = .8 # the amount of height reserved for white space between subplots plt.subplots_adjust( left= left #, bottom=bottom, right=right, top=top, wspace=wspace, hspace=hspace ) plt.tight_layout() #init hover tooltip # create a long tooltip with newline to get around wx bug (in v2.6.3.3) # where newlines aren't recognized on subsequent self.tooltip.SetTip() calls self.tooltip = wx.ToolTip( tip='tip with a long %s line and a newline\n') self.canvas.SetToolTip(self.tooltip) self.tooltip.Enable(False) self.tooltip.SetDelay(0) #init lists #self.lines = {} self.lines = [] self.axislist = {} self.curveindex = -1 self.editseriesID = -1 self.editCurve = None self.editPoint = None self.hoverAction = None self.selplot = None self.cursors = [] self.canvas.draw() self._init_sizers() def _init_sizers(self): # generated method, don't edit self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL) self._init_coll_boxSizer1_Items(self.boxSizer1) self.SetSizer(self.boxSizer1) ''' def changePlotSelection(self, datetime_list=[]): cc= ColorConverter() # k black, # r red # needs to have graph first selected = cc.to_rgba('r', 1) unselected = cc.to_rgba('k', 0.1) allunselected = cc.to_rgba('k', 1) if self.editPoint: colorlist=[allunselected] *len(self.editCurve.dataTable) if len(datetime_list)>0: for i in xrange(len(self.editCurve.dataTable)): if self.editCurve.dataTable[i][1] in datetime_list: colorlist[i]=selected else: colorlist[i]=unselected self.editPoint.set_color(colorlist) #self.editPoint.set_color(['k' if x == 0 else 'r' for x in tflist]) self.canvas.draw() ''' ## TODO 10/15/2014 Change function so that it will accept a list of datavalues. This will remove the need to loop through the values currently plotted and we would instead plot the list of datetimes and datavalues together. def changePlotSelection(self, filtered_datetime): """ Selected points have a scatter plot drawn over them to indicated the point being selected """ if self.selplot: self.selplot.remove() del self.selplot self.selplot = None result = None if isinstance(filtered_datetime, pd.DataFrame): result = filtered_datetime.sort_index() if isinstance(filtered_datetime, list): df = self.editCurve.dataTable result = df[df['LocalDateTime'].isin(filtered_datetime)].astype( datetime.datetime) if isinstance(result, pd.DataFrame): if result.empty: self.canvas.draw() return else: if not result: self.canvas.draw() return values = result['DataValue'].values.tolist() dates = result.index.astype(datetime.datetime) self.selplot = self.axislist[self.editSeries.axisTitle].scatter( dates, values, s=35, c='red', edgecolors='none', zorder=12, marker='s', alpha=1) self.canvas.draw() def lassoChangeSelection(self, filtered_datetime): self.parent.record_service.select_points(dataframe=filtered_datetime) def onShowLegend(self, isVisible): if isVisible: self.isShowLegendEnabled = True plt.subplots_adjust(bottom=.1 + .1) leg = self.timeSeries.legend(loc='upper right', ncol=2, fancybox=True, prop=self.fontP) leg.get_frame().set_alpha(.5) leg.draggable(state=True) else: self.isShowLegendEnabled = False plt.subplots_adjust(bottom=.1) self.timeSeries.legend_ = None plt.gcf().autofmt_xdate() self.canvas.draw() def onPlotType(self, ptype): # self.timeSeries.clear() if ptype == "line": ls = '-' m = 'None' elif ptype == "point": ls = 'None' m = 'o' else: ls = '-' m = 'o' self.format = ls + m for k, v in self.axislist.iteritems(): lines = v.get_lines() for line in lines: plt.setp(line, linestyle=ls, marker=m) if self.isShowLegendEnabled: self.onShowLegend(self.isShowLegendEnabled) plt.gcf().autofmt_xdate() self.canvas.draw() def stopEdit(self): self.clear() self.selectedlist = None self.selplot = None self.lman = None #self.canvas.mpl_disconnect(self.hoverAction) try: self.canvas.mpl_disconnect(self.pointPick) self.pointPick = None except AttributeError as e: logger.error(e) self.hoverAction = None self.xys = None self.alpha = 1 self.curveindex = -1 self.editCurve = None # self.RefreshPlot() if self.seriesPlotInfo and self.seriesPlotInfo.isPlotted( self.editseriesID): self.updatePlot() self.toolbar.stopEdit() self.editseriesID = -1 def updateValues(self): # self.addEdit(self.editCursor, self.editSeries, self.editDataFilter) #clear current edit points and curve if self.editCurve: curraxis = self.axislist[self.editCurve.axisTitle] for l in curraxis.lines: if l.get_label() == self.editCurve.plotTitle: curraxis.lines.remove(l) #redraw editpoints and curve self.seriesPlotInfo.updateEditSeries() self.editCurve = self.seriesPlotInfo.getEditSeriesInfo() self.drawEditPlot(self.editCurve) self.canvas.draw() Publisher.sendMessage("refreshTable", e=self.editCurve.dataTable) # self.parent.parent.dataTable.Refresh() plt.gcf().autofmt_xdate() self.canvas.draw() def drawEditPlot(self, oneSeries): self.axislist[oneSeries.axisTitle].set_zorder(10) self.lines[self.curveindex] = self.axislist[oneSeries.axisTitle] data = oneSeries.dataTable dates = data.index.astype(datetime.datetime) curraxis = self.axislist[oneSeries.axisTitle] curraxis.plot_date(dates, data['DataValue'], "-s", color=oneSeries.color, xdate=True, label=oneSeries.plotTitle, zorder=10, alpha=1, picker=5.0, pickradius=5.0, markersize=4.5) curraxis.set_xlabel('Date') convertedDates = matplotlib.dates.date2num(dates) self.xys = zip(convertedDates, oneSeries.dataTable['DataValue']) self.toolbar.editSeries(self.xys, self.editCurve) self.pointPick = self.canvas.mpl_connect('pick_event', self._onPick) self.editSeries = oneSeries def _setColor(self, color): """Set figure and canvas colours to be the same. :rtype : object """ plt.gcf().set_facecolor(color) plt.gcf().set_edgecolor(color) self.canvas.SetBackgroundColour(color) def close(self): #plt.clf() #plt.close() pass def Plot(self, seriesPlotInfo): self.seriesPlotInfo = seriesPlotInfo self.updatePlot() # resets the home view - will remove any previous zooming self.toolbar.update() self.toolbar.push_current() #self._views.home() #self._positions.home() #self.set_history_buttons() #clear plot def clear(self): """ :return: """ lines = [] for key, ax in self.axislist.items(): ax.clear() self.axislist = {} #self.canvas.draw() # self.stopEdit() #print "TimeSeries: ", dir(self.timeSeries), type(self.timeSeries) #plt.cla() #plt.clf() #self.timeSeries.plot([], [], picker=5) def setUpYAxis(self): """ Setting up multiple axes :return: """ self.axislist = {} left = 0 right = 0 adj = .05 editaxis = None ## Identify Axes and save them to axislist #loop through the list of curves and add an axis for each for oneSeries in self.seriesPlotInfo.getAllSeries(): #test to see if the axis already exists if oneSeries.edit: editaxis = oneSeries.axisTitle if not oneSeries.axisTitle in self.axislist: self.axislist[oneSeries.axisTitle] = None keys = self.axislist.keys() ## Put editing axis at the beginning of the list if editaxis: for i in range(len(keys)): if keys[i] == editaxis: keys.pop(i) break keys.insert(0, editaxis) leftadjust = -30 for i, axis in zip(range(len(self.axislist)), keys): if i % 2 == 0: left = left + 1 #add to the left(yaxis) if i == 0: #if first plot use the orig axis newAxis = self.timeSeries else: newAxis = self.timeSeries.twinx() ''' Spines idea #newAxis.spines["left"].set_position(("axes", leftadjust * left)) newAxis.spines["left"].set_position(("axes", -.1)) newAxis.spines["left"].set_visible(True) newAxis.yaxis.set_label_position("left") newAxis.yaxis.set_ticks_position("left") ''' new_fixed_axis = newAxis.get_grid_helper().new_fixed_axis newAxis.axis['left'] = new_fixed_axis(loc='left', axes=newAxis, offset=(leftadjust * left, 0)) newAxis.axis["left"].toggle(all=True) newAxis.axis["right"].toggle(all=False) leftadjust -= 15 else: right = right + 1 #add to the right(y2axis) newAxis = self.timeSeries.twinx() ''' Spines idea #newAxis.spines["right"].set_position(("axes", -1*60*(right - 1))) newAxis.spines["right"].set_position(("axes", 1.0)) newAxis.spines["right"].set_visible(True) newAxis.yaxis.set_label_position("right") newAxis.yaxis.set_ticks_position("right") ''' new_fixed_axis = newAxis.get_grid_helper().new_fixed_axis newAxis.axis['right'] = new_fixed_axis(loc='right', axes=newAxis, offset=(60 * (right - 1), 0)) newAxis.axis['right'].toggle(all=True) a = newAxis.set_ylabel(axis, picker=True) a.set_picker(True) #logger.debug("axis label: %s" % (axis)) self.axislist[axis] = newAxis plt.tight_layout() self.canvas.draw() def updatePlot(self): self.clear() count = self.seriesPlotInfo.count() self.setUpYAxis() self.lines = [] ## Spine initialization ## for oneSeries in self.seriesPlotInfo.getAllSeries(): if oneSeries.seriesID == self.seriesPlotInfo.getEditSeriesID(): """ Edited Series """ self.curveindex = len(self.lines) self.lines.append("") self.editCurve = oneSeries self.drawEditPlot(oneSeries) else: """ Plotted Series """ curraxis = self.axislist[oneSeries.axisTitle] curraxis.set_zorder(1) data = oneSeries.dataTable dates = data.index.astype(datetime.datetime) #data.plot(ax=curraxis) curraxis.plot_date(dates, data['DataValue'], color=oneSeries.color, fmt=self.format, xdate=True, tz=None, antialiased=True, label=oneSeries.plotTitle, alpha=self.alpha, picker=5.0, pickradius=5.0, markersize=4) curraxis.set_xlabel('Date') ''' data = oneSeries.dataTable #dates = data['LocalDateTime'].astype(datetime.datetime) data['LocalDateTime'] = pd.to_datetime(data['LocalDateTime']) data['LocalDateTime'].astype(datetime.datetime) data.plot(ax=curraxis) oneSeries.dataTable.plot(ax=curraxis) curraxis.set_xlabel('Date') ''' if count > 1: self.setTimeSeriesTitle("") plt.subplots_adjust(bottom=.1 + .1) # self.timeSeries.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), # ncol=2, prop = self.fontP) self.timeSeries.legend(loc='upper center', bbox_to_anchor=(0.5, -1.75), ncol=2, prop=self.fontP) elif count == 0: self.setTimeSeriesTitle("") self.timeSeries.legend_ = None else: self.setTimeSeriesTitle(oneSeries.siteName) plt.subplots_adjust(bottom=.1) self.timeSeries.legend_ = None self.timeSeries.set_xlabel("Date", picker=True) #self.timeSeries.set_xlim(matplotlib.dates.date2num([self.seriesPlotInfo.currentStart, self.seriesPlotInfo.currentEnd])) #self.timeSeries.axis[:].set_major_formatter(FormatStrFormatter('%.2f')) self.timeSeries.axis[:].major_ticks.set_tick_out(True) self.timeSeries.axis["bottom"].label.set_pad(20) self.timeSeries.axis["bottom"].major_ticklabels.set_pad(15) self.timeSeries.axis["bottom"].major_ticklabels.set_rotation(15) self.timeSeries.axis[:].major_ticklabels.set_picker(True) plt.gcf().autofmt_xdate() #self.figure.tight_layout() if not self.toolbar._views.empty(): for v in self.toolbar._views: del (v) self.toolbar.push_current() self.canvas.draw() def updateCursor(self, selectedObject=None, deselectedObject=None): """ :param selectedObject: """ try: if selectedObject: """ Activate Cursor. Happens when a plot is selected """ if self.seriesPlotInfo: seriesInfo = self.seriesPlotInfo.getSeries( selectedObject.id) if seriesInfo: currentAxis = None # If there a key with the axisTitle we are interested in, set currentaxis to that. if seriesInfo.axisTitle in self.axislist.keys(): currentAxis = self.axislist[seriesInfo.axisTitle] # If nothing is in the axislist, we don't care about it elif len(self.axislist) < 1: currentAxis = None self.configureCursor(currentAxis=currentAxis) elif deselectedObject: """ Deactivate Cursor. This happens when the plot is deselected """ self.deactivateCursor(deselectedObject) except AttributeError as e: print "Ignoring Attribute Error", e def deactivateCursor(self, deselectedObject=None): # Remove an object if supplied if deselectedObject: for i in self.cursors: if i.selected == deselectedObject: i.disable() break # Disable existing Cursors elif self.cursors: for i in self.cursors: i.disable() def configureCursor(self, currentAxis=None): """Creates the cursors for each axes in order to provide data hovering""" self.deactivateCursor() self.cursors = [] # initialize cursors for axes from currently selected axes for k, v in self.axislist.iteritems(): i = Cursor(self.canvas, self.toolbar, v, k) ## If I have selected an axis that is in the axislist if v == currentAxis: i.enable() i.setSelected(currentAxis) # If there is only one axis in the axislist, default to the first axis elif len(self.axislist) == 1: i.enable() i.setSelected(self.axislist.values()[0]) # Else I disable the other axes that I don't care about else: i.setSelected(None) i.disable() self.cursors.append(i) def setTimeSeriesTitle(self, title=""): """Set the title of the TimeSeries plot""" self.timeSeries.set_title(title, picker=True) def setEdit(self, id): self.editseriesID = id self.alpha = .5 if self.seriesPlotInfo and self.seriesPlotInfo.isPlotted( self.editseriesID): self.editCurve = self.seriesPlotInfo.getSeries(self.editseriesID) ## TODO Duplicate UpdatePlot? logger.debug("Called duplicate updateplot") self.updatePlot() def make_patch_spines_invisible(self, ax): ax.set_frame_on(True) ax.patch.set_visible(False) for sp in ax.spines.itervalues(): sp.set_visible(False) def _onMotion(self, event): """ :type event: matplotlib.backend_bases.MouseEvent :return: """ try: if event.xdata and event.ydata: xValue = matplotlib.dates.num2date( event.xdata).replace(tzinfo=None) #self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%Y-%m-%d %H:%M:%S"), event.ydata)) #self.toolbar.msg.SetLabelText("X= %s, Y= %.2f" % (xValue.strftime("%b %d, %Y %H:%M:%S"), event.ydata)) self.toolbar.msg.SetLabelText( "X= %s, Y= %.2f" % (xValue.strftime("%b %d, %Y %H:%M"), event.ydata)) self.toolbar.msg.SetForegroundColour((66, 66, 66)) else: self.toolbar.msg.SetLabelText("") except ValueError: pass def _onPick(self, event): """ :param event: :return: """ if isinstance(event.artist, Line2D): thisline = event.artist xdata = thisline.get_xdata() ydata = thisline.get_ydata() ind = event.ind xValue = xdata[ind][0] yValue = ydata[ind][0] #tip = '(%s, %s)' % (xValue.strftime("%Y-%m-%d %H:%M:%S"), yValue) #tip = '(%s, %s)' % (xValue.strftime("%b %d, %Y %H:%M:%S"), yValue) tip = '(%s, %s)' % (xValue.strftime("%b %d, %Y %H:%M"), yValue) self.tooltip.SetTip(tip) self.tooltip.Enable(True) self.tooltip.SetAutoPop(10000) elif isinstance(event.artist, Text): text = event.artist #print "Picking Label: ", text.get_text() def _onFigureLeave(self, event): """Catches mouse leaving the figure :param event: :return: """ if self.tooltip.Window.Enabled: self.tooltip.SetTip("")
class plotProb(wx.Panel): def _init_coll_boxSizer1_Items(self, parent): # generated method, don't edit parent.AddWindow(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) parent.AddWindow(self.toolbar, 0, wx.EXPAND) def _init_sizers(self): # generated method, don't edit self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL) self._init_coll_boxSizer1_Items(self.boxSizer1) self.SetSizer(self.boxSizer1) def clear(self): self.figure.clear() def close(self): #self.plot.clf() self.plots.close('all') def _init_ctrls(self, prnt): #matplotlib.figure.Figure.__init__(self) wx.Panel.__init__(self, prnt, -1) self.figure = Figure() ax = self.figure.add_subplot(111) ax.axis([0, 1, 0, 1]) # ax.plot([], []) ax.set_title("No Data To Plot") self.islegendvisible = False self.canvas = FigCanvas(self, -1, self.figure) # Create the navigation toolbar, tied to the canvas self.toolbar = NavigationToolbar(self.canvas) self.toolbar.Realize() self.axislist = {} left = 0.125 # the left side of the subplots of the figure right = 0.9 # the right side of the subplots of the figure bottom = 0.51 # the bottom of the subplots of the figure top = 1.2 # the top of the subplots of the figure wspace = .8 # the amount of width reserved for blank space between subplots hspace = .8 # the amount of height reserved for white space between subplots self.figure.subplots_adjust( left=left, bottom=bottom, right=right, top=top, wspace=wspace, hspace=hspace ) self.figure.tight_layout() #self.canvas.SetCursor(wx.StockCursor(wx.CURSOR_CROSS)) #self.canvas.SetScrollbar(wx.HORIZONTAL, 0,5, 1000) self.setColor("WHITE") self.canvas.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma')) self.fontP = FontProperties() self.fontP.set_size('small') self.canvas.draw() self._init_sizers() def onPlotType(self, ptype): # self.timeSeries.clear() if ptype == "line": ls = '-' m = 'None' elif ptype == "point": ls = 'None' m = 's' else: ls = '-' m = 's' # print plt.setp(self.lines) # print(len(self.lines)) self.format = ls + m for _, line in self.axislist.iteritems(): plt.setp(line, linestyle=ls, marker=m) if self.islegendvisible: self.onShowLegend(self.islegendvisible) self.canvas.draw() def onShowLegend(self, isVisible): self.islegendvisible = isVisible if isVisible: leg = self.plots.legend(loc='upper right', ncol=2, fancybox=True, prop=self.fontP) leg.get_frame().set_alpha(.5) leg.draggable(state=True) else: self.plots.legend_ = None self.canvas.draw() def Plot(self, seriesPlotInfo): self.seriesPlotInfo = seriesPlotInfo self.updatePlot() def updatePlot(self): self.clear() count = self.seriesPlotInfo.count() # keep track of all of the axes self.axislist = {} self.plots = self.figure.add_subplot(111) for oneSeries in self.seriesPlotInfo.getAllSeries(): self.plots.set_xlabel("Cumulative Frequency < Stated Value %") if count > 1: self.plots.set_ylabel("\n".join(textwrap.wrap(oneSeries.axisTitle, 50))) self.plots.set_title("") else: self.plots.set_ylabel("\n".join(textwrap.wrap(oneSeries.axisTitle, 50))) self.plots.set_title("\n".join(textwrap.wrap(oneSeries.siteName, 55))) if len(oneSeries.dataTable) > 0: #self.prob.append( #prop = oneSeries.Probability.plot(column="DataValue", ax=self.plots) #todo FutureWarning: order is deprecated, use sort_values(...) #xValues = oneSeries.Probability.xAxis.order().values xValues = oneSeries.Probability.xAxis.order().values # yValues = oneSeries.Probability.yAxis.order().values yValues = oneSeries.Probability.yAxis.order().values ax = self.plots.plot(xValues, yValues, 'bs', color=oneSeries.color, label=oneSeries.plotTitle) self.axislist[oneSeries.axisTitle] = ax[0] self.setXaxis() '''if count > 1: plt.subplots_adjust(bottom=.1 + .1) self.plot.legend(loc='upper center', ncol=2, prop=self.fontP) else: plt.subplots_adjust(bottom=.1) self.plot.legend_ = None''' #if len(self.plots)>0: self.figure.tight_layout() self.canvas.draw() def addPlot(self, cursor, series, Filter): # self.cursor = Values[0] self.cursor = cursor self.cursor.execute("SELECT DataValue FROM DataValues" + Filter) self.dataValues = [x[0] for x in self.cursor.fetchall()] self.Series = series self.plots.clear() length = len(self.dataValues) self.Yaxis = sorted(self.dataValues) self.Xaxis = [] for it in range(0, length): curFreq = self.calcualteProbabilityFreq(it + 1, length) curX = self.calculateProbabilityXPosition(curFreq) self.Xaxis.append(curX) self.plots.clear() x = range(len(self.Xaxis)) self.plots.set_xlabel("Cumulative Frequency < Stated Value %") self.plots.set_ylabel( "\n".join(textwrap.wrap(self.Series.variable_name + " (" + self.Series.variable_units_name + ")", 50))) self.plots.set_title("\n".join(textwrap.wrap(self.Series.site_name + " " + self.Series.variable_name, 55))) self.plots = self.figure.add_subplot(111) self.prob = self.plots.plot(self.Xaxis, self.Yaxis, 'bs') #self.figure.autofmt_xdate() self.setXaxis() self.canvas.draw() def setXaxis(self): self.plots.set_xbound(1, 100) def setColor(self, color): """Set figure and canvas colours to be the same.""" self.figure.set_facecolor(color) self.figure.set_edgecolor(color) self.canvas.SetBackgroundColour(color) def __init__(self, parent, id, pos, size, style, name): self._init_ctrls(parent)