Python bokeh.models.LinearAxis() Examples
The following are 9
code examples of bokeh.models.LinearAxis().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bokeh.models
, or try the search function
.
Example #1
Source File: __init__.py From marconibot with GNU General Public License v3.0 | 5 votes |
def plotCCI(p, df, plotwidth=800, upcolor='orange', downcolor='yellow'): # create y axis for rsi p.extra_y_ranges = {"cci": Range1d(start=min(df['cci'].values), end=max(df['cci'].values))} p.add_layout(LinearAxis(y_range_name="cci"), 'right') candleWidth = (df.iloc[2]['date'].timestamp() - df.iloc[1]['date'].timestamp()) * plotwidth # plot green bars inc = df.cci >= 0 p.vbar(x=df.date[inc], width=candleWidth, top=df.cci[inc], bottom=0, fill_color=upcolor, line_color=upcolor, alpha=0.5, y_range_name="cci", legend='cci') # Plot red bars dec = df.cci < 0 p.vbar(x=df.date[dec], width=candleWidth, top=0, bottom=df.cci[dec], fill_color=downcolor, line_color=downcolor, alpha=0.5, y_range_name="cci", legend='cci')
Example #2
Source File: __init__.py From marconibot with GNU General Public License v3.0 | 5 votes |
def plotVolume(p, df, plotwidth=800, upcolor='green', downcolor='red', colname='volume'): candleWidth = (df.iloc[2]['date'].timestamp() - df.iloc[1]['date'].timestamp()) * plotwidth # create new y axis for volume p.extra_y_ranges = {colname: Range1d(start=min(df[colname].values), end=max(df[colname].values))} p.add_layout(LinearAxis(y_range_name=colname), 'right') # Plot green candles inc = df.close > df.open p.vbar(x=df.date[inc], width=candleWidth, top=df[colname][inc], bottom=0, alpha=0.1, fill_color=upcolor, line_color=upcolor, y_range_name=colname) # Plot red candles dec = df.open > df.close p.vbar(x=df.date[dec], width=candleWidth, top=df[colname][dec], bottom=0, alpha=0.1, fill_color=downcolor, line_color=downcolor, y_range_name=colname)
Example #3
Source File: figureenvelope.py From backtrader_plotting with GNU General Public License v3.0 | 5 votes |
def plot_volume(self, data: bt.AbstractDataBase, alpha=1.0, extra_axis=False): """extra_axis displays a second axis (for overlay on data plotting)""" source_id = FigureEnvelope._source_id(data) self._add_columns([(source_id + 'volume', np.float64), (source_id + 'colors_volume', np.object)]) kwargs = {'fill_alpha': alpha, 'line_alpha': alpha, 'name': 'Volume', 'legend_label': 'Volume'} ax_formatter = NumeralTickFormatter(format=self._scheme.number_format) if extra_axis: source_data_axis = 'axvol' self.figure.extra_y_ranges = {source_data_axis: DataRange1d( range_padding=1.0/self._scheme.volscaling, start=0, )} # use colorup ax_color = convert_color(self._scheme.volup) ax = LinearAxis(y_range_name=source_data_axis, formatter=ax_formatter, axis_label_text_color=ax_color, axis_line_color=ax_color, major_label_text_color=ax_color, major_tick_line_color=ax_color, minor_tick_line_color=ax_color) self.figure.add_layout(ax, 'left') kwargs['y_range_name'] = source_data_axis else: self.figure.yaxis.formatter = ax_formatter vbars = self.figure.vbar('index', get_bar_width(), f'{source_id}volume', 0, source=self._cds, fill_color=f'{source_id}colors_volume', line_color="black", **kwargs) # make sure the new axis only auto-scales to the volume data if extra_axis: self.figure.extra_y_ranges['axvol'].renderers = [vbars] self._hoverc.add_hovertip("Volume", f"@{source_id}volume{{({self._scheme.number_format})}}", data)
Example #4
Source File: visualization.py From minian with GNU General Public License v3.0 | 5 votes |
def _twinx(self, plot, element): # Setting the second y axis range name and range start, end = (element.range(1)) label = element.dimensions()[1].pprint_label plot.state.extra_y_ranges = {"foo": Range1d(start=start, end=end)} # Adding the second axis to the plot. linaxis = LinearAxis(axis_label=label, y_range_name='foo') plot.state.add_layout(linaxis, 'right')
Example #5
Source File: plot.py From arlpy with BSD 3-Clause "New" or "Revised" License | 4 votes |
def freqz(b, a=1, fs=2.0, worN=None, whole=False, degrees=True, style='solid', thickness=1, title=None, xlabel='Frequency (Hz)', xlim=None, ylim=None, width=None, height=None, hold=False, interactive=None): """Plot frequency response of a filter. This is a convenience function to plot frequency response, and internally uses :func:`scipy.signal.freqz` to estimate the response. For further details, see the documentation for :func:`scipy.signal.freqz`. :param b: numerator of a linear filter :param a: denominator of a linear filter :param fs: sampling rate in Hz (optional, normalized frequency if not specified) :param worN: see :func:`scipy.signal.freqz` :param whole: see :func:`scipy.signal.freqz` :param degrees: True to display phase in degrees, False for radians :param style: line style ('solid', 'dashed', 'dotted', 'dotdash', 'dashdot') :param thickness: line width in pixels :param title: figure title :param xlabel: x-axis label :param ylabel1: y-axis label for magnitude :param ylabel2: y-axis label for phase :param xlim: x-axis limits (min, max) :param ylim: y-axis limits (min, max) :param width: figure width in pixels :param height: figure height in pixels :param interactive: enable interactive tools (pan, zoom, etc) for plot :param hold: if set to True, output is not plotted immediately, but combined with the next plot >>> import arlpy >>> arlpy.plot.freqz([1,1,1,1,1], fs=120000); """ w, h = _sig.freqz(b, a, worN, whole) Hxx = 20*_np.log10(abs(h)+_np.finfo(float).eps) f = w*fs/(2*_np.pi) if xlim is None: xlim = (0, fs/2) if ylim is None: ylim = (_np.max(Hxx)-50, _np.max(Hxx)+10) figure(title=title, xlabel=xlabel, ylabel='Amplitude (dB)', xlim=xlim, ylim=ylim, width=width, height=height, interactive=interactive) _hold_enable(True) plot(f, Hxx, color=color(0), style=style, thickness=thickness, legend='Magnitude') fig = gcf() units = 180/_np.pi if degrees else 1 fig.extra_y_ranges = {'phase': _bmodels.Range1d(start=-_np.pi*units, end=_np.pi*units)} fig.add_layout(_bmodels.LinearAxis(y_range_name='phase', axis_label='Phase (degrees)' if degrees else 'Phase (radians)'), 'right') phase = _np.angle(h)*units fig.line(f, phase, line_color=color(1), line_dash=style, line_width=thickness, legend_label='Phase', y_range_name='phase') _hold_enable(hold)
Example #6
Source File: __init__.py From marconibot with GNU General Public License v3.0 | 4 votes |
def plotRSI(p, df, plotwidth=800, upcolor='green', downcolor='red', yloc='right', limits=(30, 70)): # create y axis for rsi p.extra_y_ranges = {"rsi": Range1d(start=0, end=100)} p.add_layout(LinearAxis(y_range_name="rsi"), yloc) p.add_layout(Span(location=limits[0], dimension='width', line_color=upcolor, line_dash='dashed', line_width=2, y_range_name="rsi")) p.add_layout(Span(location=limits[1], dimension='width', line_color=downcolor, line_dash='dashed', line_width=2, y_range_name="rsi")) candleWidth = (df.iloc[2]['date'].timestamp() - df.iloc[1]['date'].timestamp()) * plotwidth # plot green bars inc = df.rsi >= 50 p.vbar(x=df.date[inc], width=candleWidth, top=df.rsi[inc], bottom=50, fill_color=upcolor, line_color=upcolor, alpha=0.5, y_range_name="rsi") # Plot red bars dec = df.rsi <= 50 p.vbar(x=df.date[dec], width=candleWidth, top=50, bottom=df.rsi[dec], fill_color=downcolor, line_color=downcolor, alpha=0.5, y_range_name="rsi")
Example #7
Source File: bokeh_timeline.py From pyglet with BSD 3-Clause "New" or "Revised" License | 4 votes |
def make_plot(info, outfile): # prepare some data (wall_times, pyglet_times, audio_times, current_times, frame_nums, rescheds, x_vnones, y_vnones, x_anones, y_anones) = info # output to static HTML file output_file(outfile) # main plot p = figure( tools="pan,wheel_zoom,reset,save", y_axis_type="linear", y_range=[0.000, wall_times[-1]], title="timeline", x_axis_label='wall_time', y_axis_label='time', plot_width=600, plot_height=600 ) # add some renderers p.line(wall_times, wall_times, legend="wall_time") #p.line(wall_times, pyglet_times, legend="pyglet_time", line_width=3) p.line(wall_times, current_times, legend="current_times", line_color="red") p.line(wall_times, audio_times, legend="audio_times", line_color="orange", line_dash="4 4") p.circle(x_vnones, y_vnones, legend="current time nones", fill_color="green", size=8) p.circle(x_anones, y_anones, legend="audio time nones", fill_color="red", size=6) # secondary y-axis for frame_num p.extra_y_ranges = {"frame_num": Range1d(start=0, end=frame_nums[-1])} p.line(wall_times, frame_nums, legend="frame_num", line_color="black", y_range_name="frame_num") p.add_layout(LinearAxis(y_range_name="frame_num", axis_label="frame num"), 'left') p.legend.location = "bottom_right" # show the results #show(p) # secondary plot for rescheduling times q = figure( tools="pan,wheel_zoom,reset,save", y_axis_type="linear", y_range=[-0.3, 0.3], title="rescheduling time", x_axis_label='wall_time', y_axis_label='rescheduling time', plot_width=600, plot_height=150 ) q.line(wall_times, rescheds) show(column(p, q))
Example #8
Source File: bokeh.py From histogrammar-python with Apache License 2.0 | 4 votes |
def plot(xLabel='x',yLabel='y',*args): from bokeh.models import DataRange1d, Plot, LinearAxis, Grid from bokeh.models import PanTool, WheelZoomTool xdr = DataRange1d() ydr = DataRange1d() plot = Plot(x_range=xdr, y_range=ydr, min_border=80) extra = list() if type(xLabel) is not str and type(yLabel) is not str: extra.append(xLabel) extra.append(yLabel) xLabel = 'x' yLabel = 'y' elif type(xLabel) is not str: extra.append(xLabel) xLabel = 'x' elif type(yLabel) is not str: extra.append(yLabel) yLabel = 'y' args = extra+list(args) for renderer in args: if type(renderer) is not list: plot.renderers.append(renderer) else: plot.renderers.extend(renderer) #axes xaxis = LinearAxis(axis_label=xLabel) plot.add_layout(xaxis, 'below') yaxis = LinearAxis(axis_label=yLabel) plot.add_layout(yaxis, 'left') #add grid to the plot #plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) #plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) #interactive tools plot.add_tools(PanTool(), WheelZoomTool()) #, SaveTool()) return plot
Example #9
Source File: health.py From choochoo with GNU General Public License v2.0 | 4 votes |
def std_distance_time_plot(nx, ny, source, x_range=None, output_backend=DEFAULT_BACKEND): # avoid range errors if len(source[N.ACTIVE_TIME_S].dropna()) < 2: return None groups = [group for statistic, group in related_statistics(source, N.ACTIVE_TIME)] if not groups: # original monochrome plot return multi_dot_plot(nx, ny, N.TIME, [N.ACTIVE_TIME_H, N.ACTIVE_DISTANCE_KM], source, ['black', 'grey'], alphas=[1, 0.5], x_range=x_range, rescale=True) times = [f'{N.ACTIVE_TIME}:{group}' for group in groups] distances = [f'{N.ACTIVE_DISTANCE}:{group}' for group in groups] time_y_range = make_range(source[N.ACTIVE_TIME_H]) distance_y_range = make_range(source[N.ACTIVE_DISTANCE_KM]) colours = list(evenly_spaced_hues(len(groups))) tooltip_names = [N.ACTIVE_TIME_H, N.ACTIVE_DISTANCE_KM, N.ACTIVITY_GROUP, N.LOCAL_TIME] tooltip_names += [name for name in like(N._delta(N.FITNESS_ANY), source.columns) if ':' not in name] tooltip_names += [name for name in like(N._delta(N.FATIGUE_ANY), source.columns) if ':' not in name] tools = [PanTool(dimensions='width'), ZoomInTool(dimensions='width'), ZoomOutTool(dimensions='width'), ResetTool(), HoverTool(tooltips=[tooltip(name) for name in tooltip_names], names=['with_hover'])] f = figure(output_backend=output_backend, plot_width=nx, plot_height=ny, x_axis_type='datetime', tools=tools) f.yaxis.axis_label = f'lines - {N.ACTIVE_TIME_H}' f.y_range = time_y_range f.extra_y_ranges = {N.ACTIVE_DISTANCE: distance_y_range} f.add_layout(LinearAxis(y_range_name=N.ACTIVE_DISTANCE, axis_label=f'dots - {N.ACTIVE_DISTANCE_KM}'), 'right') plotter = comb_plotter() for time, colour, group in zip(times, colours, groups): time_h = N._slash(time, Units.H) source[time_h] = source[time] / 3600 source[N.ACTIVITY_GROUP] = group plotter(f, x=N.TIME, y=time_h, source=source, color=colour, alpha=1) plotter = dot_plotter() for distance, colour, group in zip(distances, colours, groups): distance_km = N._slash(distance, Units.KM) source[distance_km] = source[distance] source[N.ACTIVITY_GROUP] = group plotter(f, x=N.TIME, y=distance_km, source=source, color=colour, alpha=1, name='with_hover', y_range_name=N.ACTIVE_DISTANCE) f.xaxis.axis_label = N.TIME f.toolbar.logo = None if ny < 300: f.toolbar_location = None if x_range: f.x_range = x_range return f