def _create_barplots(self): # Get the size of each individual bin bin_width = self.bar_width / self.nbvars barplots = [] for (i, v) in zip(self.indices, self.values): index = ArrayDataSource(i) index_range = DataRange1D(index, low= -0.5, high=self.nbdata + 0.5, tight_bounds=True) index_mapper = LinearMapper(range=index_range) # value = ArrayDataSource(v) value_range = DataRange1D(value, tight_bounds=True) value_mapper = LinearMapper(range=value_range) barplot = BarPlot(index=index, index_mapper=index_mapper, value=value, value_mapper=value_mapper, line_color=0x111111, labels=self.labels, bar_width=bin_width, antialias=True) barplot.padding = 30 barplots.append(barplot) self.barplots = barplots return barplots
def __init__(self, link): super(TrackingView, self).__init__() self.link = link self.link.add_callback(MSG_TRACKING_SNRS, self.tracking_snrs_callback) # ======= Line Plot ======= self.plot_data = ArrayPlotData(t=[0.0]) self.plot = Plot(self.plot_data, auto_colors=colours_list) self.plot.value_range.tight_bounds = False self.plot.value_range.low_setting = 0.0 for n in range(TRACK_N_CHANNELS): self.plot_data.set_data('ch'+str(n), [0.0]) self.plot.plot(('t', 'ch'+str(n)), type='line', color='auto') # ======= Bar Plot ======= idxs = ArrayDataSource(range(1, len(self.snrs)+1)) self.vals = ArrayDataSource(self.snrs, sort_order='none') # Create the index range index_range = DataRange1D(idxs, low=0.4, high=TRACK_N_CHANNELS+0.6) index_mapper = LinearMapper(range=index_range) # Create the value range value_range = DataRange1D(low=0.0, high=25.0) value_mapper = LinearMapper(range=value_range) plot = BarPlot(index=idxs, value=self.vals, index_mapper=index_mapper, value_mapper=value_mapper, line_color='blue', fill_color='blue', bar_width=0.8) container = OverlayPlotContainer(bgcolor = "white") plot.padding = 10 plot.padding_left = 30 plot.padding_bottom = 30 container.add(plot) left_axis = PlotAxis(plot, orientation='left') bottom_axis = LabelAxis(plot, orientation='bottom', labels = map(str, range(1, TRACK_N_CHANNELS+1)), positions = range(1, TRACK_N_CHANNELS+1), small_haxis_style=True) plot.underlays.append(left_axis) plot.underlays.append(bottom_axis) self.snr_bars = container self.python_console_cmds = { 'track': self }
def _plot_default(self): container = OverlayPlotContainer(bgcolor = "white") self.idx = ArrayDataSource( range(1, self.binsNum+1) ) self.vals = ArrayDataSource(self.value_points, sort_order="none") index_range = DataRange1D(self.idx, low=0, high=self.binsNum+2 ) index_mapper = LinearMapper(range=index_range) value_range = DataRange1D(low=0, high=self.value_points.max()) value_mapper = LinearMapper(range=value_range) # Create the plot self.histPlot = BarPlot(index=self.idx, value=self.vals, value_mapper=value_mapper, index_mapper=index_mapper, line_color='black', fill_color=tuple(COLOR_PALETTE[1]), bar_width=0.8, antialias=False) plots = [self.histPlot] for plot in plots: plot.padding = 50 plot.padding_left = 80 plot.padding_top = 30 container.add(plot) left_axis = PlotAxis(plot, orientation='left', title='Number / Probability', positions = [num for num in self.value_points], labels = ["%.2f" % num for num in self.value_points], #small_haxis_style=True ) bottom_axis = LabelAxis(plot, orientation='bottom', title='Values', positions = range(1, self.binsNum+1), labels = ["%.2f" % num for num in self.index_points], ) plot.underlays.append(left_axis) plot.underlays.append(bottom_axis) return container
def request_redraw_delayed(self): self.redraw_timer.Stop() BarPlot.request_redraw(self)
class ChacoHistogram(HasTraits): plot = Instance(Component) view = View( Group( Item('plot', editor=ComponentEditor(size=(500, 500)), show_label=False), orientation='vertical'), resizable=True, title='Statistics') def updateCuts(self, min, max): self.currentMin = min self.currentMax = max def setHistParams(self, binsNum, normed, valuesArray): self.normed = normed self.valuesArray = valuesArray self.binsNum = binsNum try: min = self.currentMin max = self.currentMax minCutValues = self.valuesArray[ numpy.nonzero(self.valuesArray >= self.currentMin)[0] ] minMaxCutValues = minCutValues[ numpy.nonzero(minCutValues <= self.currentMax)[0] ] self.valuesArray = minMaxCutValues except: pass pts = numpy.histogram(self.valuesArray, bins = binsNum, normed = self.normed) centerBinsCoords = [ (pts[1][num] + pts[1][num+1])/2.0 for num in range(len(pts[1])-1) ] self.value_points = pts[0] self.index_points = centerBinsCoords def _plot_default(self): container = OverlayPlotContainer(bgcolor = "white") self.idx = ArrayDataSource( range(1, self.binsNum+1) ) self.vals = ArrayDataSource(self.value_points, sort_order="none") index_range = DataRange1D(self.idx, low=0, high=self.binsNum+2 ) index_mapper = LinearMapper(range=index_range) value_range = DataRange1D(low=0, high=self.value_points.max()) value_mapper = LinearMapper(range=value_range) # Create the plot self.histPlot = BarPlot(index=self.idx, value=self.vals, value_mapper=value_mapper, index_mapper=index_mapper, line_color='black', fill_color=tuple(COLOR_PALETTE[1]), bar_width=0.8, antialias=False) plots = [self.histPlot] for plot in plots: plot.padding = 50 plot.padding_left = 80 plot.padding_top = 30 container.add(plot) left_axis = PlotAxis(plot, orientation='left', title='Number / Probability', positions = [num for num in self.value_points], labels = ["%.2f" % num for num in self.value_points], #small_haxis_style=True ) bottom_axis = LabelAxis(plot, orientation='bottom', title='Values', positions = range(1, self.binsNum+1), labels = ["%.2f" % num for num in self.index_points], ) plot.underlays.append(left_axis) plot.underlays.append(bottom_axis) return container def updatePlot(self): left_axis = PlotAxis(self.histPlot, orientation='left', title='Number / Probability', positions = [num for num in self.value_points], labels = ["%.2f" % num for num in self.value_points]) bottom_axis = LabelAxis(self.histPlot, orientation='bottom', title='Values', positions = range(1, self.binsNum+1), labels = ["%.2f" % num for num in self.index_points]) self.histPlot.underlays = [left_axis, bottom_axis] # self.idx = ArrayDataSource( range(1, self.binsNum+1) ) self.vals = ArrayDataSource(self.value_points, sort_order="none") index_range = DataRange1D(self.idx, low=0, high=self.binsNum+2 ) value_range = DataRange1D(low=0, high=self.value_points.max()) self.histPlot.index.set_data( range(1, self.binsNum+1) ) self.histPlot.value.set_data( self.value_points, sort_order="none" ) self.histPlot.index_mapper.range = index_range self.histPlot.value_mapper.range = value_range self.histPlot.request_redraw()