def container_factory(self): """ """ kw = {'type': 'v', 'stack_order': 'top_to_bottom'} for k, v in self.container_dict.items(): kw[k] = v return container_factory(**kw)
def load_graph(self, reader, window_title=''): cg = ContourGraph( container_dict=dict(kind='h', # padding=40, # shape=(2, 2), # spacing=(12, 12) ) ) z, metadata = self._extract_power_map_data(reader) self._data = z self._metadata = metadata center_plot = cg.new_plot( add=False, padding=0, width=400, height=400, resizable='' # aspect_ratio=1 ) center_plot.index_axis.visible = False center_plot.value_axis.visible = False # from skimage.morphology import label # z = label(z) bounds = metadata['bounds'] # center_plot, names, rd = cg.new_series(z=z, style='contour', cg.new_series(z=z, style='contour', xbounds=bounds, ybounds=bounds, ) bottom_plot = cg.new_plot( add=False, height=150, resizable='h', padding=0, xtitle='mm', ytitle='power') right_plot = cg.new_plot( add=False, width=150, resizable='v', padding=0, xtitle='mm', ytitle='power') right_plot.x_axis.orientation = 'right' # right_plot.x_axis.title = 'mm' right_plot.y_axis.orientation = 'top' # right_plot.y_axis.title = 'power' center = center_plot.plots['plot0'][0] options = dict(style='cmap_scatter', type='cmap_scatter', marker='circle', color_mapper=center.color_mapper) cg.new_series(plotid=1, render_style='connectedpoints') cg.new_series(plotid=1, **options) right_plot.x_axis.orientation = 'right' right_plot.y_axis.orientation = 'top' right_plot.x_axis.mapper = center_plot.value_mapper right_plot.y_axis.mapper = bottom_plot.value_mapper right_plot.x_axis.axis_line_visible = False right_plot.y_axis.axis_line_visible = False s = cg.new_series(plotid=2, render_style='connectedpoints')[0] s.orientation = 'v' s = cg.new_series(plotid=2, **options)[0] s.orientation = 'v' center.index.on_trait_change(cg.metadata_changed, 'metadata_changed') cg.show_crosshairs('blue') # z = self._plot_properties(z, metadata, cg) # cg.plots[0].data.set_data('z0', z) gridcontainer = container_factory(kind='g', padding=40, shape=(2, 2), spacing=(12, 12)) gridcontainer.add(center_plot) gridcontainer.add(right_plot) gridcontainer.add(bottom_plot) cb = cg.make_colorbar(center) cb.width = 50 cb.padding_left = 50 cg.plotcontainer.add(cb) cg.plotcontainer.add(gridcontainer) self.graph = cg return cg
def _graph_contour(self, x, y, z, r, reg, refresh): cg = self.graph if not isinstance(cg, FluxVisualizationGraph): cg = FluxVisualizationGraph(container_dict={ 'kind': 'h', 'bgcolor': self.plotter_options.bgcolor }) self.graph = cg else: cg.clear() center_plot = cg.new_plot(xtitle='X', ytitle='Y', add=False, padding=0, width=550, height=550, resizable='', aspect_ratio=1) ito = IrradiationTrayOverlay(component=center_plot, geometry=self.geometry, show_labels=self.show_labels) self.irradiation_tray_overlay = ito center_plot.overlays.append(ito) gx, gy, m, me = self._model_flux(reg, r) # self._visualization_update(gx, gy, m, me, reg.xs, reg.ys) r = r * 1.1 s, p = cg.new_series(z=m, xbounds=(-r, r), ybounds=(-r, r), levels=self.levels, cmap=self.color_map_name, colorbar=True, style='contour') # add data tool def predict_func(ptx, pty): return floatfmt(reg.predict([(ptx, pty)])[0], n=2, use_scientific=True, s=6) dt = DataTool(plot=s, filter_components=False, predict_value_func=predict_func, use_date_str=False, component=p) dto = DataToolOverlay(component=p, tool=dt) p.tools.append(dt) p.overlays.append(dto) # add slice inspectors cg.add_inspectors(s) # add 1D slices bottom_plot = cg.new_plot(add=False, height=175, resizable='h', padding=0, xtitle='mm', ytitle='J') right_plot = cg.new_plot( add=False, width=175, resizable='v', padding=0, # xtitle='J', ytitle='mm') center = center_plot.plots['plot0'][0] options = dict(style='cmap_scatter', type='cmap_scatter', marker='circle', color_mapper=center.color_mapper) cg.new_series(plotid=1, render_style='connectedpoints') cg.new_series(plotid=1, **options) s = cg.new_series(plotid=1, type='scatter', marker_size=2, color='red', style='xy', marker='circle')[0] ebo = ErrorBarOverlay(component=s, orientation='y', use_component=False) s.underlays.append(ebo) x, y = reg.xs.T ebo.index, ebo.value, ebo.error = x, reg.ys, reg.yserr cg.bottom_error_bars = ebo center_plot.x_axis.orientation = 'top' right_plot.orientation = 'v' right_plot.x_axis.orientation = 'top' right_plot.x_axis.tick_label_rotate_angle = 45 right_plot.y_axis.orientation = 'right' right_plot.x_axis.axis_line_visible = False right_plot.y_axis.axis_line_visible = False s = cg.new_series(plotid=2, render_style='connectedpoints')[0] s.orientation = 'v' s = cg.new_series(plotid=2, **options)[0] s.orientation = 'v' ss = cg.new_series(plotid=2, type='scatter', marker_size=2, color='red', style='xy', marker='circle')[0] ss.orientation = 'v' ebo = ErrorBarOverlay(component=ss, orientation='x', use_component=False) ss.underlays.append(ebo) x, y = reg.xs.T ebo.index, ebo.value, ebo.error = y, reg.ys, reg.yserr cg.right_error_bars = ebo center.index.on_trait_change(cg.metadata_changed, 'metadata_changed') gridcontainer = container_factory( kind='g', # fill_padding=True, # bgcolor='red', padding_left=100, padding_right=20, padding_top=100, padding_bottom=40, shape=(2, 2), spacing=(5, 5)) gridcontainer.add(center_plot) gridcontainer.add(right_plot) gridcontainer.add(bottom_plot) # cb = cg.make_colorbar(center) # cb.width = 50 # cb.padding_left = 50 # cg.plotcontainer.add(cb) # plot means s = cg.new_series(x, y, z=z, style='cmap_scatter', color_mapper=s.color_mapper, marker='circle', marker_size=self.marker_size) cg.errors = reg.yserr cg.x = reg.xs cg.y = reg.ys cg.plotcontainer.add(gridcontainer)
def new_series(self, x=None, y=None, plotid=0, **kw): """ """ plot, scatter, _line = super(ResidualsGraph, self).new_series(x=x, y=y, plotid=plotid, **kw) for underlay in plot.underlays: if underlay.orientation == 'bottom': underlay.visible = False underlay.padding_bottom = 0 plot.padding_bottom = 0 x, y, res = self.calc_residuals(plotid=plotid) ressplit = self._split_residual(x, res) resneg = ArrayDataSource(ressplit[1]) xneg = ArrayDataSource(ressplit[0]) respos = ArrayDataSource(ressplit[3]) xpos = ArrayDataSource(ressplit[2]) yrange = DataRange1D(ArrayDataSource(res)) ymapper = LinearMapper(range=yrange) container = container_factory(type='o', padding=[50, 15, 0, 30], height=75, resizable='h') bar = BarPlot(index=xneg, value=resneg, index_mapper=scatter.index_mapper, value_mapper=ymapper, bar_width=0.2, line_color='blue', fill_color='blue', border_visible=True) # left_axis = PlotAxis(bar, orientation = 'left') # bottom_axis=PlotAxis(bar,orientation='bottom') kw = dict(vtitle='residuals') if self.xtitle: kw['htitle'] = self.xtitle add_default_axes(bar, **kw) hgrid = PlotGrid(mapper=ymapper, component=bar, orientation='horizontal', line_color='lightgray', line_style='dot') bar.underlays.append(hgrid) # bar.underlays.append(left_axis) # bar.underlays.append(bottom_axis) bar2 = BarPlot(index=xpos, value=respos, index_mapper=scatter.index_mapper, value_mapper=ymapper, bar_width=0.2, line_color='green', fill_color='green', # bgcolor = 'green', resizable='hv', border_visible=True, # padding = [30, 5, 0, 30] ) bar2.overlays.append(GuideOverlay(bar2, value=0, color=(0, 0, 0))) bar2.underlays.append(hgrid) container.add(bar) container.add(bar2) # container.add(PlotLabel('foo')) self.residual_plots = [bar, bar2] self.plotcontainer.add(container)
def new_series(self, x=None, y=None, plotid=0, **kw): """ """ plot, scatter, _line = super(ResidualsGraph, self).new_series(x=x, y=y, plotid=plotid, **kw) for underlay in plot.underlays: if underlay.orientation == 'bottom': underlay.visible = False underlay.padding_bottom = 0 plot.padding_bottom = 0 x, y, res = self.calc_residuals(plotid=plotid) ressplit = self._split_residual(x, res) resneg = ArrayDataSource(ressplit[1]) xneg = ArrayDataSource(ressplit[0]) respos = ArrayDataSource(ressplit[3]) xpos = ArrayDataSource(ressplit[2]) yrange = DataRange1D(ArrayDataSource(res)) ymapper = LinearMapper(range=yrange) container = container_factory(type='o', padding=[50, 15, 0, 30], height=75, resizable='h') bar = BarPlot(index=xneg, value=resneg, index_mapper=scatter.index_mapper, value_mapper=ymapper, bar_width=0.2, line_color='blue', fill_color='blue', border_visible=True) # left_axis = PlotAxis(bar, orientation = 'left') # bottom_axis=PlotAxis(bar,orientation='bottom') kw = dict(vtitle='residuals') if self.xtitle: kw['htitle'] = self.xtitle add_default_axes(bar, **kw) hgrid = PlotGrid(mapper=ymapper, component=bar, orientation='horizontal', line_color='lightgray', line_style='dot') bar.underlays.append(hgrid) # bar.underlays.append(left_axis) # bar.underlays.append(bottom_axis) bar2 = BarPlot( index=xpos, value=respos, index_mapper=scatter.index_mapper, value_mapper=ymapper, bar_width=0.2, line_color='green', fill_color='green', # bgcolor = 'green', resizable='hv', border_visible=True, # padding = [30, 5, 0, 30] ) bar2.overlays.append(GuideOverlay(bar2, value=0, color=(0, 0, 0))) bar2.underlays.append(hgrid) container.add(bar) container.add(bar2) # container.add(PlotLabel('foo')) self.residual_plots = [bar, bar2] self.plotcontainer.add(container)
def _graph_contour(self, x, y, z, r, reg, refresh): cg = self.graph if not isinstance(cg, FluxVisualizationGraph): cg = FluxVisualizationGraph(container_dict={'kind': 'h', 'bgcolor': self.plotter_options.bgcolor}) self.graph = cg else: cg.clear() center_plot = cg.new_plot(xtitle='X', ytitle='Y', add=False, padding=0, width=550, height=550, resizable='', aspect_ratio=1) ito = IrradiationTrayOverlay(component=center_plot, geometry=self.geometry, show_labels=self.show_labels) self.irradiation_tray_overlay = ito center_plot.overlays.append(ito) gx, gy, m, me = self._model_flux(reg, r) # self._visualization_update(gx, gy, m, me, reg.xs, reg.ys) r = r * 1.1 s, p = cg.new_series(z=m, xbounds=(-r, r), ybounds=(-r, r), levels=self.levels, cmap=self.color_map_name, colorbar=True, style='contour') # add data tool def predict_func(ptx, pty): return floatfmt(reg.predict([(ptx, pty)])[0], n=2, use_scientific=True, s=6) dt = DataTool(plot=s, filter_components=False, predict_value_func=predict_func, use_date_str=False, component=p) dto = DataToolOverlay(component=p, tool=dt) p.tools.append(dt) p.overlays.append(dto) # add slice inspectors cg.add_inspectors(s) # add 1D slices bottom_plot = cg.new_plot(add=False, height=175, resizable='h', padding=0, xtitle='mm', ytitle='J') right_plot = cg.new_plot(add=False, width=175, resizable='v', padding=0, # xtitle='J', ytitle='mm') center = center_plot.plots['plot0'][0] options = dict(style='cmap_scatter', type='cmap_scatter', marker='circle', color_mapper=center.color_mapper) cg.new_series(plotid=1, render_style='connectedpoints') cg.new_series(plotid=1, **options) s = cg.new_series(plotid=1, type='scatter', marker_size=2, color='red', style='xy', marker='circle')[0] ebo = ErrorBarOverlay(component=s, orientation='y', use_component=False) s.underlays.append(ebo) x, y = reg.xs.T ebo.index, ebo.value, ebo.error = x, reg.ys, reg.yserr cg.bottom_error_bars = ebo center_plot.x_axis.orientation = 'top' right_plot.orientation = 'v' right_plot.x_axis.orientation = 'top' right_plot.x_axis.tick_label_rotate_angle = 45 right_plot.y_axis.orientation = 'right' right_plot.x_axis.axis_line_visible = False right_plot.y_axis.axis_line_visible = False s = cg.new_series(plotid=2, render_style='connectedpoints')[0] s.orientation = 'v' s = cg.new_series(plotid=2, **options)[0] s.orientation = 'v' ss = cg.new_series(plotid=2, type='scatter', marker_size=2, color='red', style='xy', marker='circle')[0] ss.orientation = 'v' ebo = ErrorBarOverlay(component=ss, orientation='x', use_component=False) ss.underlays.append(ebo) x, y = reg.xs.T ebo.index, ebo.value, ebo.error = y, reg.ys, reg.yserr cg.right_error_bars = ebo center.index.on_trait_change(cg.metadata_changed, 'metadata_changed') gridcontainer = container_factory(kind='g', # fill_padding=True, # bgcolor='red', padding_left=100, padding_right=20, padding_top=100, padding_bottom=40, shape=(2, 2), spacing=(5, 5)) gridcontainer.add(center_plot) gridcontainer.add(right_plot) gridcontainer.add(bottom_plot) # cb = cg.make_colorbar(center) # cb.width = 50 # cb.padding_left = 50 # cg.plotcontainer.add(cb) # plot means s = cg.new_series(x, y, z=z, style='cmap_scatter', color_mapper=s.color_mapper, marker='circle', marker_size=self.marker_size) cg.errors = reg.yserr cg.x = reg.xs cg.y = reg.ys cg.plotcontainer.add(gridcontainer)