def _draw9Objects(): """ Histogram The following must be true: len(bspec) = len(hist_data) + 1 """ data = 2.25 * np.random.randn(50) + 3 heights, bins = np.histogram(data, bins=10) hist_fixed_binsize = wxplot.PolyHistogram(heights, bins) # Bins can also be arbitrary widths: hist_variable_binsize = wxplot.PolyHistogram( [2, 3, 4, 6, 3], [18, 19, 22, 25, 26, 27], fillcolour=wx.BLUE, edgewidth=2, edgecolour=wx.RED, ) return wxplot.PlotGraphics( [hist_fixed_binsize, hist_variable_binsize], "Histogram with fixed binsize (left) and variable binsize (right)", "Value", "Count", )
def OnDrawGraph(self, evt): # simple line plot if evt.GetId() == self.idLine: # clear previous plot self.pnlPlot.Clear() x = np.linspace(0, 10, 500) y = np.sin(x) # create lines line1 = wxplot.PolyLine(list(zip(x, np.sin(x))), colour='red', width=3, style=wx.PENSTYLE_DOT_DASH) line2 = wxplot.PolyLine(list(zip(x, -np.sin(x))), colour='blue', width=3, style=wx.PENSTYLE_LONG_DASH) # create a graphics graphics = wxplot.PlotGraphics([line1, line2]) self.pnlPlot.Draw(graphics) # histogram elif evt.GetId() == self.idHist: # clear previous plot self.pnlPlot.Clear() np.random.seed(0) # fixed bins on the right x1 = np.random.normal(400, 25, size=100) h1, b1 = np.histogram(x1, bins=8) hist1 = wxplot.PolyHistogram(h1, b1, fillcolour='red') # variable bins on the left x2 = np.random.normal(200, 25, size=100) h2, b2 = np.histogram( x2, bins=[100, 150, 180, 195, 205, 220, 250, 300]) hist2 = wxplot.PolyHistogram(h2, b2, fillcolour='blue') # graph title and axis titles graphics = wxplot.PlotGraphics( [hist1, hist2], 'Histogram with variable binsize and fixed binsize', 'value', 'count') self.pnlPlot.Draw(graphics)
def update(self, data, binspec): self.Clear() # other stuff uses numpy so I can too. hist, edges = np.histogram(data, binspec) bars = [] for n, (count, (low, high)) in enumerate(zip(hist, pairwise(edges))): pts = [(low, 0), (low, count)] ln = wxplot.PolyLine( pts, colour='blue', width=3, ) bars.append(ln) # hack to get things to look like a "bar"... pts2 = [(high, 0), (high, count)] ln2 = wxplot.PolyLine( pts2, colour='blue', width=3, ) bars.append(ln2) pts3 = [(low, count), (high, count)] ln3 = wxplot.PolyLine( pts3, colour='blue', width=3, ) bars.append(ln3) bars = [wxplot.PolyHistogram(hist, edges)] plot = wxplot.PlotGraphics( bars, title=self.title, xLabel=self.x_label, yLabel=self.y_label, ) self.XSpec = (0, 75) self.EnableGrid = True self.Draw(plot)
def drawHistogram(self, binData, histData, xTicks): self.statGraph.Clear() if not binData or not histData: return hist = wxplot.PolyHistogram(histData, binData, fillcolour=wx.BLUE, edgecolour=wx.BLACK) graphics = wxplot.PlotGraphics([hist], title=self.selectedSingleVariable + ' histogram', xLabel=self.selectedSingleVariable, yLabel='count') binSz = binData[1] - binData[0] self.statGraph.setXticks(xTicks) self.statGraph.Draw( graphics, (binData[0] - 0.5 * binSz, binData[-1] + 0.5 * binSz), (0, max(histData) * 1.05))