def gen_line_plot(series_one, series_two, y_axis_name=''): """ Parameters ---------- series_one : nd array series_two : nd array """ size = min(series_one.shape[0], series_two.shape[0]) idx = ArrayDataSource(arange(size)) series_one_data = ArrayDataSource(series_one[:size]) series_two_data = ArrayDataSource(series_two[:size]) y_range = DataRange1D(series_one_data) y_range.tight_bounds = False y_range.margin = 50 x_mapper = LinearMapper(range=DataRange1D(idx)) y_mapper = LinearMapper(range=y_range) series_one_plot = LinePlot(index=idx, value=series_one_data, index_mapper=x_mapper, value_mapper=y_mapper, color='blue') series_two_plot = LinePlot(index=idx, value=series_two_data, index_mapper=x_mapper, value_mapper=y_mapper, color='red') container = OverlayPlotContainer(bgcolor='white', padding=25, fill_padding=False, border_visible=True) y_axis = PlotAxis(mapper=y_mapper, component=container, orientation='left') x_axis = PlotAxis(mapper=x_mapper, component=container, orientation='bottom') x_axis.title = 'Time' y_axis.title = y_axis_name legend = Legend(component=container, padding=10, align='ur') legend.plots = { 'Predicted': series_one_plot, 'Actual': series_two_plot, } container.add(series_one_plot) container.add(series_two_plot) container.overlays.append(y_axis) container.overlays.append(legend) return container
def _plots_default(self): plotdata = self.get_data_sets() plots = Plot(plotdata) plotsDict = {} # plot background sonar image and impound lines xbounds = self.model.survey_rng_m ybounds = self.model.depth_m plots.img_plot("sonarimg", colormap=jet, xbounds=xbounds, ybounds=ybounds) ip = plots.plot(('impound1_X','impound1_Y'), type='line', marker='square') plotsDict['Impoundment line'] = ip plots.x_axis.title = 'Distance along survey line (m)' plots.y_axis.title = 'Depth (m)' # add core samples as scatter with separate y-axis corex = plotdata.get_data('coreX') corey = plotdata.get_data('coreY') scatter = create_scatter_plot((corex,corey), marker='diamond', color='red' ) scatter.index_range = plots.index_range axis = PlotAxis(scatter, orientation='right') axis.title = 'Core sample dist from survey line (m)' scatter.underlays.append(axis) plots.add(scatter) # create vertical line for indicating selected core sample position vals1 = [0 for x in corey] vline = create_line_plot((corey,vals1), color='blue', orientation='v') vline.value_range = scatter.index_range plots.add(vline) # Add Legend legend = Legend(component=plots, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="left")) legend.plots = plotsDict plots.overlays.append(legend) # Add tools scatter.tools.append(PickTool(scatter)) plots.tools.append(TraceTool(plots)) plots.tools.append(PanTool(plots)) plots.tools.append(ZoomTool(plots)) return plots
def _create_plot_component(): container = OverlayPlotContainer(padding=60, fill_padding=True, use_backbuffer=True, border_visible=True) # Create the initial X-series of data numpoints = 100 low = -5 high = 15.0 x = arange(low, high + 0.001, (high - low) / numpoints) # Plot some bessel functions plots = {} broadcaster = BroadcasterTool() for i in range(4): y = jn(i, x) plot = create_line_plot((x, y), color=tuple(COLOR_PALETTE[i]), width=2.0) if i == 0: add_default_grids(plot) left_axis, _ = add_default_axes(plot) left_axis.title = "Bessel j0, j2, j3" elif i != 1: # Map correctly j2 and j3 on the first plot's axis: plot0 = plots["Bessel j_0"] plot.index_mapper = plot0.index_mapper plot.value_mapper = plot0.value_mapper plot0.value_mapper.range.add(plot.value) # Create a pan/zoom tool and give it a reference to the plot it should # manipulate, but don't attach it to the plot. Instead, attach it to # the broadcaster. Do it only for each independent set of axis_mappers: if i in [0, 1]: pan = PanTool(component=plot) broadcaster.tools.append(pan) zoom = ZoomTool(component=plot) broadcaster.tools.append(zoom) container.add(plot) plots["Bessel j_%d" % i] = plot # Add an axis on the right-hand side that corresponds to the second plot. # Note that it uses plot.value_mapper instead of plot0.value_mapper. plot1 = plots["Bessel j_1"] axis = PlotAxis(plot1, orientation="right") plot1.underlays.append(axis) axis.title = "Bessel j1" # Add the broadcast tool to one of the renderers: adding it to the # container instead breaks the box mode of the ZoomTool: plot0 = plots["Bessel j_0"] plot0.tools.append(broadcaster) # Create a legend, with tools to move it around and highlight renderers: legend = Legend(component=container, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="right")) legend.tools.append(LegendHighlighter(legend)) container.overlays.append(legend) # Set the list of plots on the legend legend.plots = plots # Add the title at the top container.overlays.append( PlotLabel("Bessel functions", component=container, font="swiss 16", overlay_position="top")) # Add the traits inspector tool to the container container.tools.append(TraitsTool(container)) return container