How to use the bokeh.models.Range1d function in bokeh

To help you get started, we’ve selected a few bokeh examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bokeh / bokeh / tests / glyphs / Gear.py View on Github external
def epicyclic_gear(module, sun_teeth, planet_teeth):
    xdr = Range1d(start=-150, end=150)
    ydr = Range1d(start=-150, end=150)

    plot = Plot(
    title=None, x_range=xdr, y_range=ydr, plot_width=300, plot_height=300,
    h_symmetry=False, v_symmetry=False, min_border=0, toolbar_location=None)

    annulus_teeth = sun_teeth + 2*planet_teeth

    glyph = Gear(
        x=0, y=0,
        module=module, teeth=annulus_teeth, angle=0,
        fill_color=fill_color[0], line_color=line_color, internal=True
    )
    plot.add_glyph(glyph)

    glyph = Gear(
        x=0, y=0,
github bokeh / bokeh / tests / integration / widgets / test_text_input.py View on Github external
def modify_doc(doc):
    source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], val=["a", "b"]))
    plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
    plot.add_glyph(source, Circle(x='x', y='y', size=20))
    plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data"))))
    text_input = TextInput(css_classes=["foo"])
    def cb(attr, old, new):
        source.data['val'] = [old, new]
    text_input.on_change('value', cb)
    doc.add_root(column(text_input, plot))
github bokeh / bokeh / tests / integration / widgets / test_slider.py View on Github external
def modify_doc(doc):
            source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], val=["a", "b"]))
            plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
            plot.add_glyph(source, Circle(x='x', y='y', size=20))
            plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data"))))
            slider = Slider(start=0, end=10, value=1, title="bar", css_classes=["foo"], width=300)

            def cb(attr, old, new):
                source.data['val'] = [old, new]

            slider.on_change('value', cb)
            doc.add_root(column(slider, plot))
github bokeh / bkcharts / bkcharts / builders / boxplot_builder.py View on Github external
:source-position: above

        from bkcharts import BoxPlot, output_file, show
        from bokeh.layouts import row
        from bokeh.sampledata.autompg import autompg as df

        box = BoxPlot(df, values='mpg', label='cyl', title="Auto MPG Box Plot", plot_width=400)
        box2 = BoxPlot(df, values='mpg', label='cyl', color='cyl',
                       title="MPG Box Plot by Cylinder Count", plot_width=400)

        output_file('box.html')
        show(row(box, box2))

    """

    if continuous_range and not isinstance(continuous_range, Range1d):
        raise ValueError(
            "continuous_range must be an instance of bokeh.models.ranges.Range1d"
        )

    # The continuous_range is the y_range (until we implement HBar charts)
    y_range = continuous_range
    kw['label'] = label
    kw['values'] = values
    kw['color'] = color
    kw['group'] = group
    kw['xscale'] = xscale
    kw['yscale'] = yscale
    kw['xgrid'] = xgrid
    kw['ygrid'] = ygrid
    kw['y_range'] = y_range
github FeatureLabs / henchman / henchman / plotting.py View on Github external
'''
    if figargs['width'] is not None:
        plot.width = figargs['width']
    if figargs['height'] is not None:
        plot.height = figargs['height']

    if figargs['title'] is not None:
        plot.title.text = figargs['title']
    if figargs['x_axis'] is not None:
        plot.xaxis.axis_label = figargs['x_axis']
    if figargs['y_axis'] is not None:
        plot.yaxis.axis_label = figargs['y_axis']

    if figargs['x_range'] is not None:
        plot.x_range = Range1d(figargs['x_range'][0], figargs['x_range'][1])
    if figargs['y_range'] is not None:
        plot.y_range = Range1d(figargs['y_range'][0], figargs['y_range'][1])

    return plot
github flatironinstitute / CaImAn / caiman / utils / visualization.py View on Github external
def nb_imshow(image, cmap='jet'):
    """
    Interactive equivalent of imshow for ipython notebook
    """
    colormap = cm.get_cmap(cmap)  # choose any matplotlib colormap here
    grayp = [mpl.colors.rgb2hex(m) for m in colormap(np.arange(colormap.N))]
    xr = Range1d(start=0, end=image.shape[1])
    yr = Range1d(start=image.shape[0], end=0)
    p = bpl.figure(x_range=xr, y_range=yr)

    p.image(image=[image[::-1, :]], x=0, y=image.shape[0],
            dw=image.shape[1], dh=image.shape[0], palette=grayp)

    return p
github pmlrsg / GISportal / plotting / plots.py View on Github external
tooltips.append(("Latitude", "@lat{1.1}"))
      tooltips.append(("Longitude", "@lon{1.1}"))

      ts_plot.add_tools(CrosshairTool())

      ts_plot.xaxis.axis_label = 'Date'
      ts_plot.title.text_font_size = "14pt"
      ts_plot.xaxis.axis_label_text_font_size = "12pt"
      ts_plot.yaxis.axis_label_text_font_size = "12pt"
      # Set up the axis label here as it writes to all y axes so overwrites the right hand one
      # if we run it later.
      debug(2,u"transect: y1Axis = {}".format(plot['y1Axis']['label']))
      ts_plot.yaxis[0].formatter = BasicTickFormatter()
      ts_plot.yaxis[0].axis_label = plot['y1Axis']['label']
      if ymin[0] != ymax[0]:
         ts_plot.y_range = Range1d(start=ymin[0], end=ymax[0])
      yrange = [None, None]

      if len(sources) > len(plot_palette[0]):
         import random
         r = lambda: random.randint(0,255)
         while len(sources) > len(plot_palette[0]):
            plot_palette[0].append('#%02X%02X%02X' % (r(),r(),r()))
            plot_palette[1].append('#%02X%02X%02X' % (r(),r(),r()))

      for i, source in enumerate(sources):
         # If we want 2 Y axes then the lines below do this
         if plot_data[i]['yaxis'] == 2 and len(ymin) > 1 and 'y2Axis' in plot.keys(): 
            debug(2, u"Plotting y2Axis, {}".format(plot['y2Axis']['label']))
            # Setting the second y axis range name and range
            yrange[1] = "y2"
            if ymin[1] != ymax[1]:
github andrewcooke / choochoo / py / ch2 / data / plot / line.py View on Github external
def histogram_plot(nx, ny, x, source, xlo=None, xhi=None, nsub=5, output_backend=DEFAULT_BACKEND):
    if not present(source, x): return None
    xlo, xhi = source[x].min() if xlo is None else xlo, source[x].max() if xhi is None else xhi
    bins = pd.interval_range(start=xlo, end=xhi, periods=nsub * (xhi - xlo), closed='left')
    c = [palettes.Inferno[int(xhi - xlo + 1)][int(b.left - xlo)] for b in bins]
    hrz_categorized = pd.cut(source[x], bins)
    counts = hrz_categorized.groupby(hrz_categorized).count()
    f = figure(output_backend=output_backend, plot_width=nx, plot_height=ny, x_range=Range1d(start=xlo, end=xhi),
               x_axis_label=x)
    f.quad(left=counts.index.categories.left, right=counts.index.categories.right, top=counts, bottom=0,
           color=c, fill_alpha=0.2)
    f.toolbar_location = None
    f.yaxis.visible = False
    return f
github spacetelescope / jwql / jwql / instrument_monitors / miri_monitors / data_trending / plots / fpe_voltage_tab.py View on Github external
# create a new plot with a title and axis labels
    p = figure( tools = "pan,wheel_zoom,box_zoom,reset,save",       \
                toolbar_location = "above",                         \
                plot_width = 560,                                   \
                plot_height = 500,                                  \
                y_range = [6.85, 7.1],                              \
                x_axis_type = 'datetime',                           \
                output_backend="webgl",                             \
                x_axis_label = 'Date', y_axis_label='Voltage (V)')

    p.grid.visible = True
    p.title.text = "FPE Ana. 7V"
    pf.add_basic_layout(p)

    p.extra_y_ranges = {"current": Range1d(start=300, end=450)}
    a = pf.add_to_plot(p, "FPE Ana. 7V", "IMIR_PDU_V_ANA_7V",start, end, conn, color = "red")
    b = pf.add_to_plot(p, "FPE Ana. 7V Current", "IMIR_PDU_I_ANA_7V",start, end, conn, y_axis = "current", color = "blue")
    p.add_layout(LinearAxis(y_range_name = "current", axis_label = "Current (mA)", axis_label_text_color = "blue"), 'right')

    pf.add_hover_tool(p,[a,b])

    p.legend.location = "bottom_right"
    p.legend.click_policy = "hide"

    return p
github andrewcooke / choochoo / ch2 / bucket / plot.py View on Github external
if y_min is None:
        return f  # bail if no data
    y_min, y_max = range_all(source2, y_axis, y_min, y_max)
    dy = y_max - y_min

    if is_x_time:
        f.xaxis[0].formatter = NumeralTickFormatter(format='00:00:00')
        zero, _ = range_all(source1, y_axis)
        for df in source1:
            df[x_axis] = (df[x_axis] - zero).total_seconds()
    else:
        f.xaxis[0].formatter = PrintfTickFormatter(format='%.2f')
    f.xaxis.axis_label = x_axis
    f.yaxis.axis_label = y_axis

    f.y_range = Range1d(start=0 if y_min == 0 else y_min - 0.1 * dy, end=y_max + 0.1 * dy)
    for df in source1:
        hover.renderers.append(f.line(x=x_axis, y=y_axis, source=df, color='black'))

    if source2:
        if is_x_time:
            zero, _ = range_all(source2, x_axis)
            for df in source2:
                df[x_axis] = (df[x_axis] - zero).total_seconds()
        for df in source2:
            hover.renderers.append(f.line(x=x_axis, y=y_axis, source=df, color='grey'))

        y1, y2 = make_series(source1, y_axis, x_axis), make_series(source2, y_axis, x_axis)
        y2 = interpolate_to_index(y1, y2)
        y1, y2, range = delta_patches(y1, y2)
        f.extra_y_ranges = {'delta': range}
        if y1 is not None: