def _make_curves(self): (index_points, value_points) = self._get_points() size = len(index_points) middle_value = 2500000.0 mid_values = middle_value * ones(size) low_values = mid_values - 10000.0 * value_points high_values = mid_values + 20000.0 * value_points idx = ArrayDataSource(index_points) vals = ArrayDataSource(low_values, sort_order="none") idx2 = ArrayDataSource(index_points) vals2 = ArrayDataSource(high_values, sort_order="none") starting_vals = ArrayDataSource(mid_values, sort_order="none") # Create the index range index_range = DataRange1D(idx, low=0.5, high=9.5) index_mapper = LinearMapper(range=index_range) # Create the value range value_range = DataRange1D(vals, vals2, low_setting='auto', high_setting='auto', tight_bounds=False) value_mapper = LinearMapper(range=value_range, tight_bounds=False) # Create the plot plot1 = BarPlot(index=idx, value=vals, value_mapper=value_mapper, index_mapper=index_mapper, starting_value=starting_vals, line_color='black', orientation='v', fill_color=tuple(COLOR_PALETTE[6]), bar_width=0.8, antialias=False) plot2 = BarPlot(index=idx2, value=vals2, value_mapper=value_mapper, index_mapper=index_mapper, starting_value=starting_vals, line_color='black', orientation='v', fill_color=tuple(COLOR_PALETTE[1]), bar_width=0.8, antialias=False) return [plot1, plot2]
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 _bar_plot_default(self): # Default data idx = np.array([1, 2, 3, 4, 5]) vals = np.array([2, 4, 7, 4, 3]) # Mappers index = ArrayDataSource(idx) index_range = DataRange1D(index, low=0.5, high=5.5) index_mapper = LinearMapper(range=index_range) value = ArrayDataSource(vals) value_range = DataRange1D(value, low=0) value_mapper = LinearMapper(range=value_range) # The bar plot plot = BarPlot( index=index, value=value, value_mapper=value_mapper, index_mapper=index_mapper, line_color="black", fill_color="cornflowerblue", bgcolor="white", bar_width=self.bar_width, line_width=self.line_width, ) return plot
def drawBar(self, indexsrc, indexmapper, valuesrc, valuemapper, color, startval=None): return BarPlot(index=indexsrc, value=valuesrc, index_mapper=indexmapper, value_mapper=valuemapper, starting_value=startval, line_color=0x202020, fill_color=color, bar_width=1.0, orientation='v')
def _create_vol_plot(self, times, volumes, height=100): "Creates and returns the volume plot" index_range = self.price_plot.index_range vol_plot = BarPlot( index=times, value=volumes, index_mapper=LinearMapper(range=index_range), value_mapper=LinearMapper(range=DataRange1D(volumes)), line_color="transparent", fill_color="black", bar_width=1.0, bar_width_type="screen", antialias=False, height=100, resizable="h", bgcolor="white", border_visible=True) vol_plot.tools.append( PanTool(vol_plot, constrain=True, constrain_direction="x")) return vol_plot
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 = self._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,orientaiton='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 _create_plot_component(): # Create the data and datasource objects numpoints = 500 index = arange(numpoints) returns = random.lognormal(0.01, 0.1, size=numpoints) price = 100.0 * cumprod(returns) volume = abs(random.normal(1000.0, 1500.0, size=numpoints) + 2000.0) time_ds = ArrayDataSource(index) vol_ds = ArrayDataSource(volume, sort_order="none") price_ds = ArrayDataSource(price, sort_order="none") xmapper = LinearMapper(range=DataRange1D(time_ds)) vol_mapper = LinearMapper(range=DataRange1D(vol_ds)) price_mapper = LinearMapper(range=DataRange1D(price_ds)) price_plot = FilledLinePlot(index=time_ds, value=price_ds, index_mapper=xmapper, value_mapper=price_mapper, edge_color="blue", face_color="paleturquoise", alpha=0.5, bgcolor="white", border_visible=True) add_default_grids(price_plot) price_plot.overlays.append(PlotAxis(price_plot, orientation='left')) price_plot.overlays.append(PlotAxis(price_plot, orientation='bottom')) price_plot.tools.append( PanTool(price_plot, constrain=True, constrain_direction="x")) price_plot.overlays.append( ZoomTool(price_plot, drag_button="right", always_on=True, tool_mode="range", axis="index")) vol_plot = BarPlot(index=time_ds, value=vol_ds, index_mapper=xmapper, value_mapper=vol_mapper, line_color="transparent", fill_color="black", bar_width=1.0, bar_width_type="screen", antialias=False, height=100, resizable="h", bgcolor="white", border_visible=True) add_default_grids(vol_plot) vol_plot.underlays.append(PlotAxis(vol_plot, orientation='left')) vol_plot.tools.append( PanTool(vol_plot, constrain=True, constrain_direction="x")) container = VPlotContainer(bgcolor="lightblue", spacing=20, padding=50, fill_padding=False) container.add(vol_plot) container.add(price_plot) container.overlays.append( PlotLabel( "Financial Plot", component=container, #font="Times New Roman 24")) font="Arial 24")) return container
def _create_plot(self): # count data if len(self.df) > 0: self.indexes = np.arange(len(self.df.date_time)) time_ds = ArrayDataSource(self.indexes) vol_ds = ArrayDataSource(self.df.volumn.values, sort_order="none") xmapper = LinearMapper(range=DataRange1D(time_ds)) vol_mapper = LinearMapper(range=DataRange1D(vol_ds)) #################################################################### # create volumn plot vol_plot = BarPlot(index=time_ds, value=vol_ds, index_mapper=xmapper, value_mapper=vol_mapper, line_color="transparent", fill_color="blue", bar_width=0.6, antialias=False, height=100, resizable="h", origin="bottom left", bgcolor="white", border_visible=True ) vol_plot.padding = 30 vol_plot.padding_left = 40 vol_plot.tools.append( PanTool(vol_plot, constrain=True, constrain_direction="x")) add_default_grids(vol_plot) add_default_axes(vol_plot) #print vol_plot.index_mapper.range.high #print vol_plot.value_mapper.range.low, vol_plot.value_mapper.range.high self.vol_plot = vol_plot self.container.add(vol_plot) #################################################################### ## Create price plot sorted_vals = np.vstack( (self.df.open, self.df.high, self.df.low, self.df.close)) sorted_vals.sort(0) __bool = self.df.close.values - self.df.open.values self.up_boolean = __bool >= 0 self.down_boolean = np.invert(self.up_boolean) pd = ArrayPlotData( up_index=self.indexes[self.up_boolean], up_min=sorted_vals[0][self.up_boolean], up_bar_min=sorted_vals[1][self.up_boolean], up_bar_max=sorted_vals[2][self.up_boolean], up_max=sorted_vals[3][self.up_boolean], down_index=self.indexes[self.down_boolean], down_min=sorted_vals[0][self.down_boolean], down_bar_min=sorted_vals[1][self.down_boolean], down_bar_max=sorted_vals[2][self.down_boolean], down_max=sorted_vals[3][self.down_boolean], volumn=self.df.volumn.values, index=self.indexes ) price_plot = Plot(pd) up_plot = price_plot.candle_plot( ("up_index", "up_min", "up_bar_min", "up_bar_max", "up_max"), color=color_red, bgcolor="azure", bar_line_color="black", stem_color="black", end_cap=False)[0] down_plot = price_plot.candle_plot( ("down_index", "down_min", "down_bar_min", "down_bar_max", "down_max"), color=color_green, bar_line_color="black", stem_color="black", end_cap=False)[0] price_plot.fill_padding = True price_plot.padding = 30 price_plot.padding_left = 40 price_plot.tools.append(ZoomTool(component=price_plot, tool_mode="box", zoom_factor=1.2, always_on=False)) price_plot.tools.append(PanTool(price_plot, drag_button="left")) price_plot.tools.append( XYTool(price_plot, callback=self._update_ohlc)) # get data self._add_line_tool(up_plot) self._add_line_tool(down_plot) price_plot.range2d = self._compute_range2d() price_plot.index_mapper = vol_plot.index_mapper # maper vol_plot and price_plot self.price_plot = price_plot self.container.add(price_plot)
def _create_plot_component(): # Create the data and datasource objects # In order for the date axis to work, the index data points need to # be in units of seconds since the epoch. This is because we are using # the CalendarScaleSystem, whose formatters interpret the numerical values # as seconds since the epoch. numpoints = 500 index = create_dates(numpoints) returns = random.lognormal(0.01, 0.1, size=numpoints) price = 100.0 * cumprod(returns) volume = abs(random.normal(1000.0, 1500.0, size=numpoints) + 2000.0) time_ds = ArrayDataSource(index) vol_ds = ArrayDataSource(volume, sort_order="none") price_ds = ArrayDataSource(price, sort_order="none") xmapper = LinearMapper(range=DataRange1D(time_ds)) vol_mapper = LinearMapper(range=DataRange1D(vol_ds)) price_mapper = LinearMapper(range=DataRange1D(price_ds)) price_plot = FilledLinePlot(index=time_ds, value=price_ds, index_mapper=xmapper, value_mapper=price_mapper, edge_color="blue", face_color="paleturquoise", bgcolor="white", border_visible=True) price_plot.overlays.append(PlotAxis(price_plot, orientation='left')), # Set the plot's bottom axis to use the Scales ticking system bottom_axis = PlotAxis( price_plot, orientation="bottom", # mapper=xmapper, tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem())) price_plot.overlays.append(bottom_axis) hgrid, vgrid = add_default_grids(price_plot) vgrid.tick_generator = bottom_axis.tick_generator price_plot.tools.append( PanTool(price_plot, constrain=True, constrain_direction="x")) price_plot.overlays.append( ZoomTool( price_plot, drag_button="right", always_on=True, tool_mode="range", axis="index", max_zoom_out_factor=10.0, )) vol_plot = BarPlot(index=time_ds, value=vol_ds, index_mapper=xmapper, value_mapper=vol_mapper, line_color="transparent", fill_color="black", bar_width=1.0, bar_width_type="screen", antialias=False, height=100, resizable="h", bgcolor="white", border_visible=True) hgrid, vgrid = add_default_grids(vol_plot) # Use the same tick generator as the x-axis on the price plot vgrid.tick_generator = bottom_axis.tick_generator vol_plot.underlays.append(PlotAxis(vol_plot, orientation='left')) vol_plot.tools.append( PanTool(vol_plot, constrain=True, constrain_direction="x")) container = VPlotContainer(bgcolor="lightblue", spacing=40, padding=50, fill_padding=False) container.add(vol_plot) container.add(price_plot) container.overlays.append( PlotLabel( "Financial Plot with Date Axis", component=container, #font="Times New Roman 24")) font="Arial 24")) return container
def _create_plot(self): # count data if len(self.df) > 0: self.indexes = np.arange(len(self.df.date_time)) time_ds = ArrayDataSource(self.indexes) vol_ds = ArrayDataSource(self.df.volumn.values, sort_order="none") xmapper = LinearMapper(range=DataRange1D(time_ds)) vol_mapper = LinearMapper(range=DataRange1D(vol_ds)) #################################################################### # create volumn plot vol_plot = BarPlot( index=time_ds, value=vol_ds, index_mapper=xmapper, value_mapper=vol_mapper, line_color="transparent", fill_color="blue", bar_width=0.6, antialias=False, height=100, resizable="h", origin="bottom left", bgcolor="white", border_visible=True, ) vol_plot.padding = 30 vol_plot.padding_left = 40 vol_plot.tools.append(PanTool(vol_plot, constrain=True, constrain_direction="x")) add_default_grids(vol_plot) add_default_axes(vol_plot) # print vol_plot.index_mapper.range.high # print vol_plot.value_mapper.range.low, vol_plot.value_mapper.range.high self.vol_plot = vol_plot self.container.add(vol_plot) #################################################################### ## Create price plot sorted_vals = np.vstack((self.df.open, self.df.high, self.df.low, self.df.close)) sorted_vals.sort(0) __bool = self.df.close.values - self.df.open.values self.up_boolean = __bool >= 0 self.down_boolean = np.invert(self.up_boolean) pd = ArrayPlotData( up_index=self.indexes[self.up_boolean], up_min=sorted_vals[0][self.up_boolean], up_bar_min=sorted_vals[1][self.up_boolean], up_bar_max=sorted_vals[2][self.up_boolean], up_max=sorted_vals[3][self.up_boolean], down_index=self.indexes[self.down_boolean], down_min=sorted_vals[0][self.down_boolean], down_bar_min=sorted_vals[1][self.down_boolean], down_bar_max=sorted_vals[2][self.down_boolean], down_max=sorted_vals[3][self.down_boolean], volumn=self.df.volumn.values, index=self.indexes, ) price_plot = Plot(pd) up_plot = price_plot.candle_plot( ("up_index", "up_min", "up_bar_min", "up_bar_max", "up_max"), color=color_red, bgcolor="azure", bar_line_color="black", stem_color="black", end_cap=False, )[0] down_plot = price_plot.candle_plot( ("down_index", "down_min", "down_bar_min", "down_bar_max", "down_max"), color=color_green, bar_line_color="black", stem_color="black", end_cap=False, )[0] price_plot.fill_padding = True price_plot.padding = 30 price_plot.padding_left = 40 price_plot.tools.append(ZoomTool(component=price_plot, tool_mode="box", zoom_factor=1.2, always_on=False)) price_plot.tools.append(PanTool(price_plot, drag_button="left")) price_plot.tools.append(XYTool(price_plot, callback=self._update_ohlc)) # get data self._add_line_tool(up_plot) self._add_line_tool(down_plot) price_plot.range2d = self._compute_range2d() price_plot.index_mapper = vol_plot.index_mapper # maper vol_plot and price_plot self.price_plot = price_plot self.container.add(price_plot)
def request_redraw_delayed(self): self.redraw_timer.Stop() BarPlot.request_redraw(self)