Python bokeh.models.Span() Examples

The following are 8 code examples of bokeh.models.Span(). 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: plot.py    From arlpy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def vlines(x, color='gray', style='dashed', thickness=1, hold=False):
    """Draw vertical lines on a plot.

    :param x: x location of lines
    :param color: line color (see `Bokeh colors`_)
    :param style: line style ('solid', 'dashed', 'dotted', 'dotdash', 'dashdot')
    :param thickness: line width in pixels
    :param hold: if set to True, output is not plotted immediately, but combined with the next plot

    >>> import arlpy.plot
    >>> arlpy.plot.plot([0, 20], [0, 10], hold=True)
    >>> arlpy.plot.vlines([7, 12])
    """
    global _figure
    if _figure is None:
        return
    x = _np.array(x, ndmin=1, dtype=_np.float, copy=False)
    for j in range(x.size):
        _figure.add_layout(_bmodels.Span(location=x[j], dimension='height', line_color=color, line_dash=style, line_width=thickness))
    if not hold and not _hold:
        _show(_figure)
        _figure = None 
Example #2
Source File: plot.py    From arlpy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def hlines(y, color='gray', style='dashed', thickness=1, hold=False):
    """Draw horizontal lines on a plot.

    :param y: y location of lines
    :param color: line color (see `Bokeh colors`_)
    :param style: line style ('solid', 'dashed', 'dotted', 'dotdash', 'dashdot')
    :param thickness: line width in pixels
    :param hold: if set to True, output is not plotted immediately, but combined with the next plot

    >>> import arlpy.plot
    >>> arlpy.plot.plot([0, 20], [0, 10], hold=True)
    >>> arlpy.plot.hlines(3, color='red', style='dotted')
    """
    global _figure
    if _figure is None:
        return
    y = _np.array(y, ndmin=1, dtype=_np.float, copy=False)
    for j in range(y.size):
        _figure.add_layout(_bmodels.Span(location=y[j], dimension='width', line_color=color, line_dash=style, line_width=thickness))
    if not hold and not _hold:
        _show(_figure)
        _figure = None 
Example #3
Source File: figureenvelope.py    From backtrader_plotting with GNU General Public License v3.0 6 votes vote down vote up
def _plot_hlines(self, obj):
        hlines = obj.plotinfo._get('plothlines', [])
        if not hlines:
            hlines = obj.plotinfo._get('plotyhlines', [])

        # Horizontal Lines
        hline_color = convert_color(self._scheme.hlinescolor)
        for hline in hlines:
            span = Span(location=hline,
                        dimension='width',
                        line_color=hline_color,
                        line_dash=convert_linestyle(self._scheme.hlinesstyle),
                        line_width=self._scheme.hlineswidth)
            self.figure.renderers.append(span) 
Example #4
Source File: annotation.py    From holoviews with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _init_glyph(self, plot, mapping, properties):
        """
        Returns a Bokeh glyph object.
        """
        box = Span(level=properties.get('level', 'glyph'), **mapping)
        plot.renderers.append(box)
        return None, box 
Example #5
Source File: dos.py    From qmpy with MIT License 4 votes vote down vote up
def bokeh_plot(self):
        if self._bokeh_plot is None:
            spinflag = False
            if len(self.dos) == 2:
                spinflag = True

            if spinflag:
                source = bkp.ColumnDataSource(data=dict(
                    en = self.energy,
                    up = self.dos[0],
                    down = -self.dos[1],
                ))
            else:
                source = bkp.ColumnDataSource(data=dict(
                    en = self.energy,
                    dos = self.dos[0],
                ))

            p = bkp.figure(width=500, height=300,
                           x_range=(-6, 6),
                           tools=['pan', 'box_zoom', 'hover', 'reset', 'save', 'help'])

            p.title.text = 'Density of States'
            p.title.align = 'center'
            p.title.text_font_size = "15pt"

            p.xaxis.axis_label = u'E \u2212 E_Fermi (eV)'
            p.xaxis.axis_label_text_font_size = '14pt'
            p.xaxis.major_label_text_font_size = '12pt'

            p.yaxis.axis_label = '# of states (arb. units)'
            p.yaxis.axis_label_text_font_size = '14pt'
            p.yaxis.major_label_text_font_size = '12pt'

            
            vline = Span(location=0, dimension='height', 
                         line_color='gray', line_width=1.5,
                         line_dash='dashed')
            p.renderers.extend([vline])

            if spinflag:
                p.line('en', 'up',   line_width = 2, line_color = 'blue',
                       legend="Spin Up",   source=source)
                p.line('en', 'down', line_width = 2, line_color = 'orange', 
                       legend="Spin Down", source=source)
            else:
                p.line('en', 'dos',  line_width = 2, line_color = 'blue',
                       legend='total',       source=source)

            p.legend.click_policy = "hide"
            self._bokeh_plot = p

        return self._bokeh_plot 
Example #6
Source File: __init__.py    From marconibot with GNU General Public License v3.0 4 votes vote down vote up
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: trial_viewer.py    From autopilot with Mozilla Public License 2.0 4 votes vote down vote up
def trial_viewer(step_data, roll_type = "ewm", roll_span=100, bar=False):
    """
    Args:
        step_data:
        grad_data:
    """
    step_data.loc[step_data['response'] == 'L','response'] = 0
    step_data.loc[step_data['response'] == 'R','response'] = 1
    step_data.loc[step_data['target'] == 'L','target'] = 0
    step_data.loc[step_data['target'] == 'R','target'] = 1

    palette = [cc.rainbow[i] for i in range(len(step_data['subject'].unique()))]
    palette = [cc.rainbow[i*15] for i in range(5)]

    mice = sorted(step_data['subject'].unique())
    current_step = step_data.groupby('subject').last().reset_index()
    current_step = current_step[['subject','step']]

    plots = []
    p = figure(x_range=step_data['subject'].unique(),title='Subject Steps',
               plot_height=200)
    p.xaxis.major_label_orientation = np.pi / 2
    p.vbar(x=current_step['subject'], top=current_step['step'], width=0.9)
    plots.append(p)
    for i, (mus, group) in enumerate(step_data.groupby('subject')):
        if roll_type == "ewm":
            meancx = group['correct'].ewm(span=roll_span,ignore_na=True).mean()
        else:
            meancx = group['correct'].rolling(window=roll_span).mean()

        title_str = "{}, step: {}".format(mus, group.step.iloc[-1])

        p = figure(plot_height=100,y_range=(0,1),title=title_str)

        if bar:
            hline = Span(location=bar, dimension="width", line_color='red', line_width=1)
            p.renderers.append(hline)

        p.line(group['trial_num'], meancx, color=palette[group['step'].iloc[0]-1])
        plots.append(p)
    grid = gridplot(plots, ncols=1)
    show(grid) 
Example #8
Source File: plot_bokeh.py    From lantern with Apache License 2.0 4 votes vote down vote up
def show(self, title='', xlabel='', ylabel='', xaxis=True, yaxis=True, xticks=True, yticks=True, legend=True, grid=True, **kwargs):
        # self.figure.add_tools(*[HoverTool(
        #     tooltips=[('x', '@x{%F}'), ('y', '@y')],
        #     formatters={'x': 'datetime'},
        #     mode='vline'
        # ) for _ in data])

        self.figure.outline_line_color = None
        # vline = Span(location=0, dimension='height', line_color='red', line_width=3)
        hline = Span(location=0, dimension='width', line_color='black', line_width=1)
        self.figure.renderers.append(hline)

        if xlabel:
            self.figure.xaxis.axis_label = kwargs.get('xlabel')
        if ylabel:
            self.figure.yaxis.axis_label = kwargs.get('ylabel')
        if title:
            self.figure.title.text = kwargs.get('title')

        if legend:
            self.figure.legend.location = (self.width + 10, self.height + 10)
            legend = Legend(items=self.legend, location=(10, 100))
            legend.items = self.legend
            legend.click_policy = "mute"
            self.figure.add_layout(legend, 'right')
        else:
            self.figure.legend.location = None

        if not grid:
            self.figure.xgrid.grid_line_color = None
            self.figure.ygrid.grid_line_color = None

        # FIXME
        if not yaxis:
            for ax in self.figure.yaxis:
                ax.axis_line_color = 'white'
        if not xaxis:
            for ax in self.figure.xaxis:
                ax.axis_line_color = 'white'

        # Turn off labels:
        # self.figure.xaxis.major_label_text_font_size = '0pt'

        show(self.figure)
        return self.figure