def _create_renderer(self): # Create our data sources bmin = _chaco.ArrayDataSource(self.ds.mat['perc25'].values) bmax = _chaco.ArrayDataSource(self.ds.mat['perc75'].values) med = _chaco.ArrayDataSource(self.ds.mat['median'].values) minv = _chaco.ArrayDataSource(self.ds.mat['min'].values) maxv = _chaco.ArrayDataSource(self.ds.mat['max'].values) idx = _chaco.ArrayDataSource(_np.arange(self.ds.n_objs)) # Create the index range index_range = _chaco.DataRange1D(idx, tight_bounds=False) index_mapper = _chaco.LinearMapper(range=index_range) # Create the value range value_range = _chaco.DataRange1D(minv, maxv, tight_bounds=False) value_mapper = _chaco.LinearMapper(range=value_range) # Color defined in enable.colors.color_table boxes = _chaco.CandlePlot(index=idx, center_values=med, bar_min=bmin, bar_max=bmax, min_values=minv, max_values=maxv, index_mapper=index_mapper, value_mapper=value_mapper, bar_color='springgreen', bar_line_color='black', center_color='forestgreen', stem_color='black', line_width=1.0, center_width=5, stem_width=1, end_cap=False) return boxes
def _create_render(self): # Create our data sources idx = _chaco.ArrayDataSource(_np.arange(self.ds.n_vars)) vals = _chaco.ArrayDataSource(self.ds.mat.ix[self.row_id].values) # Create the index range index_range = _chaco.DataRange1D(idx, tight_bounds=False, low_setting='auto', margin=0.15) index_mapper = _chaco.LinearMapper(range=index_range) # Create the value range value_range = _chaco.DataRange1D(vals, low_setting=0, high_setting=self.ceiling) value_mapper = _chaco.LinearMapper(range=value_range) # Create the plot bars = _chaco.BarPlot(index=idx, value=vals, value_mapper=value_mapper, index_mapper=index_mapper, line_color='black', fill_color='springgreen', bar_width=0.8, antialias=False) return bars
def _resplotter_default(self): res = np.zeros((400, 400)) self.pd = ArrayPlotData(res=res) p = Plot(self.pd) img = p.img_plot('res', name="my_plot") my_plot = p.plots["my_plot"][0] colormap = my_plot.color_mapper colorbar = ColorBar( index_mapper=dc.LinearMapper(range=colormap.range), color_mapper=colormap, orientation='v', plot=my_plot, resizable='v', width=30, padding=20) range_selection = RangeSelection(component=colorbar) colorbar.tools.append(range_selection) colorbar.overlays.append(RangeSelectionOverlay(component=colorbar, border_color="white", alpha=0.8, fill_color="lightgray")) range_selection.listeners.append(my_plot) con = HPlotContainer() con.add(p) con.add(colorbar) return con
def _render_data(self, pec): idx = _chaco.ArrayDataSource(_np.arange(self.ds.n_objs)) mvals = self.stair_ds # Create the index range index_range = _chaco.DataRange1D(idx, tight_bounds=False, low_setting='auto', margin=0.15) index_mapper = _chaco.LinearMapper(range=index_range) # Create the value range value_range = _chaco.DataRange1D(mvals, tight_bounds=True) value_mapper = _chaco.LinearMapper(range=value_range) colors = hue_span(mvals.get_value_size()) bar_names = {} for i in range(mvals.get_value_size() - 1, -1, -1): vals = _chaco.ArrayDataSource(mvals.get_data(axes=i)) bars = _chaco.BarPlot(index=idx, value=vals, value_mapper=value_mapper, index_mapper=index_mapper, line_color='black', fill_color=colors[i], bar_width=0.8, antialias=False) name = str(self.ds.var_n[i]) bar_names[name] = bars num = self.ds.mat.values[:, i] pecl = pec[:, i] self._add_data_labels(bars, num, pecl) self.add(bars) rvn = bar_names.keys() rvn.sort(reverse=True) legend = _chaco.Legend(component=self, padding=2, align="ur", labels=rvn) legend.plots = bar_names self.overlays.append(legend) return bars
def create_plot(self): # Create the mapper, etc self._image_index = chaco.GridDataSource(scipy.array([]), scipy.array([]), sort_order=("ascending", "ascending")) image_index_range = chaco.DataRange2D(self._image_index) self._image_index.on_trait_change(self._metadata_changed, "metadata_changed") self._image_value = chaco.ImageData(data=scipy.array([]), value_depth=1) image_value_range = chaco.DataRange1D(self._image_value) # Create the contour plots #self.polyplot = ContourPolyPlot(index=self._image_index, self.polyplot = chaco.CMapImagePlot( index=self._image_index, value=self._image_value, index_mapper=chaco.GridMapper(range=image_index_range), color_mapper=self._cmap(image_value_range)) # Add a left axis to the plot left = chaco.PlotAxis(orientation='left', title="y", mapper=self.polyplot.index_mapper._ymapper, component=self.polyplot) self.polyplot.overlays.append(left) # Add a bottom axis to the plot bottom = chaco.PlotAxis(orientation='bottom', title="x", mapper=self.polyplot.index_mapper._xmapper, component=self.polyplot) self.polyplot.overlays.append(bottom) # Add some tools to the plot self.polyplot.tools.append( tools.PanTool(self.polyplot, constrain_key="shift", drag_button="middle")) self.polyplot.overlays.append( tools.ZoomTool(component=self.polyplot, tool_mode="box", always_on=False)) self.lineInspectorX = clickableLineInspector.ClickableLineInspector( component=self.polyplot, axis='index_x', inspect_mode="indexed", write_metadata=True, is_listener=False, color="white") self.lineInspectorY = clickableLineInspector.ClickableLineInspector( component=self.polyplot, axis='index_y', inspect_mode="indexed", write_metadata=True, color="white", is_listener=False) self.polyplot.overlays.append(self.lineInspectorX) self.polyplot.overlays.append(self.lineInspectorY) self.boxSelection2D = boxSelection2D.BoxSelection2D( component=self.polyplot) self.polyplot.overlays.append(self.boxSelection2D) # Add these two plots to one container self.centralContainer = chaco.OverlayPlotContainer(padding=0, use_backbuffer=True, unified_draw=True) self.centralContainer.add(self.polyplot) # Create a colorbar cbar_index_mapper = chaco.LinearMapper(range=image_value_range) self.colorbar = chaco.ColorBar( index_mapper=cbar_index_mapper, plot=self.polyplot, padding_top=self.polyplot.padding_top, padding_bottom=self.polyplot.padding_bottom, padding_right=40, resizable='v', width=30) self.plotData = chaco.ArrayPlotData( line_indexHorizontal=scipy.array([]), line_valueHorizontal=scipy.array([]), scatter_indexHorizontal=scipy.array([]), scatter_valueHorizontal=scipy.array([]), scatter_colorHorizontal=scipy.array([]), fitLine_indexHorizontal=scipy.array([]), fitLine_valueHorizontal=scipy.array([])) self.crossPlotHorizontal = chaco.Plot(self.plotData, resizable="h") self.crossPlotHorizontal.height = 100 self.crossPlotHorizontal.padding = 20 self.crossPlotHorizontal.plot( ("line_indexHorizontal", "line_valueHorizontal"), line_style="dot") self.crossPlotHorizontal.plot( ("scatter_indexHorizontal", "scatter_valueHorizontal", "scatter_colorHorizontal"), type="cmap_scatter", name="dot", color_mapper=self._cmap(image_value_range), marker="circle", marker_size=4) self.crossPlotHorizontal.index_range = self.polyplot.index_range.x_range self.plotData.set_data("line_indexVertical", scipy.array([])) self.plotData.set_data("line_valueVertical", scipy.array([])) self.plotData.set_data("scatter_indexVertical", scipy.array([])) self.plotData.set_data("scatter_valueVertical", scipy.array([])) self.plotData.set_data("scatter_colorVertical", scipy.array([])) self.plotData.set_data("fitLine_indexVertical", scipy.array([])) self.plotData.set_data("fitLine_valueVertical", scipy.array([])) self.crossPlotVertical = chaco.Plot(self.plotData, width=140, orientation="v", resizable="v", padding=20, padding_bottom=160) self.crossPlotVertical.plot( ("line_indexVertical", "line_valueVertical"), line_style="dot") self.crossPlotVertical.plot( ("scatter_indexVertical", "scatter_valueVertical", "scatter_colorVertical"), type="cmap_scatter", name="dot", color_mapper=self._cmap(image_value_range), marker="circle", marker_size=4) self.crossPlotVertical.index_range = self.polyplot.index_range.y_range # Create a container and add components self.container = chaco.HPlotContainer(padding=40, fill_padding=True, bgcolor="white", use_backbuffer=False) inner_cont = chaco.VPlotContainer(padding=40, use_backbuffer=True) inner_cont.add(self.crossPlotHorizontal) inner_cont.add(self.centralContainer) self.container.add(self.colorbar) self.container.add(inner_cont) self.container.add(self.crossPlotVertical)