Problems with a horizontal bar chart

I’m attempting to make a horizontal bar chart as per here (http://bokeh.pydata.org/en/latest/docs/reference/models/glyphs/hbar.html). I managed to produce a ‘normal’ bar chart using high level charts but I’ve been advised that this one will look better. It just doesn’t show up with anything. I want there to be strings on y-axis and the numbers on x-axis. I’d appreciate any advice.

Attempting to make a horizontal bar chart

import numpy as np

from bokeh.models import ColumnDataSource, DataRange1d, Plot, LinearAxis, Grid

from bokeh.models.glyphs import HBar

from bokeh.io import curdoc, show

N = 12

y = esc_per_vert[‘vertical’]

x = esc_per_vert[‘perc_churned’]

source = ColumnDataSource(dict(y=y, right=x,))

xdr = DataRange1d()

ydr = DataRange1d()

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)

glyph = HBar(y=“y”, right=“right”, left=0, height=0.5, fill_color="#b3de69")

plot.add_glyph(source, glyph)

xaxis = LinearAxis()

plot.add_layout(xaxis, ‘below’)

yaxis = LinearAxis()

plot.add_layout(yaxis, ‘left’)

plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))

plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

curdoc().add_root(plot)

show(plot)

I am not 100% sure, but you might need to add the respective range specifications(xdr to xaxis, ydr to yaxis) to the new LinearAxis instance you created. This might cause the plot to not render.

···

On Wednesday, April 19, 2017 at 1:17:27 PM UTC-4, Kasia Rachuta wrote:

I’m attempting to make a horizontal bar chart as per here (http://bokeh.pydata.org/en/latest/docs/reference/models/glyphs/hbar.html). I managed to produce a ‘normal’ bar chart using high level charts but I’ve been advised that this one will look better. It just doesn’t show up with anything. I want there to be strings on y-axis and the numbers on x-axis. I’d appreciate any advice.

Attempting to make a horizontal bar chart

import numpy as np

from bokeh.models import ColumnDataSource, DataRange1d, Plot, LinearAxis, Grid

from bokeh.models.glyphs import HBar

from bokeh.io import curdoc, show

N = 12

y = esc_per_vert[‘vertical’]

x = esc_per_vert[‘perc_churned’]

source = ColumnDataSource(dict(y=y, right=x,))

xdr = DataRange1d()

ydr = DataRange1d()

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)

glyph = HBar(y=“y”, right=“right”, left=0, height=0.5, fill_color="#b3de69")

plot.add_glyph(source, glyph)

xaxis = LinearAxis()

plot.add_layout(xaxis, ‘below’)

yaxis = LinearAxis()

plot.add_layout(yaxis, ‘left’)

plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))

plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

curdoc().add_root(plot)

show(plot)

Hi,

rather than going all the way down to the bokeh.models API, which is extremely low level, I'd suggesting looking at the bokeh.plotting API which will be much less code. An example is here:

  https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/bar_chart.py

Thanks,

Bryan

···

On Apr 19, 2017, at 13:11, RiskiBizniz <[email protected]> wrote:

I am not 100% sure, but you might need to add the respective range specifications(xdr to xaxis, ydr to yaxis) to the new LinearAxis instance you created. This might cause the plot to not render.

On Wednesday, April 19, 2017 at 1:17:27 PM UTC-4, Kasia Rachuta wrote:
I'm attempting to make a horizontal bar chart as per here (http://bokeh.pydata.org/en/latest/docs/reference/models/glyphs/hbar.html). I managed to produce a 'normal' bar chart using high level charts but I've been advised that this one will look better. It just doesn't show up with anything. I want there to be strings on y-axis and the numbers on x-axis. I'd appreciate any advice.

# Attempting to make a horizontal bar chart

import numpy as np

from bokeh.models import ColumnDataSource, DataRange1d, Plot, LinearAxis, Grid
from bokeh.models.glyphs import HBar
from bokeh.io import curdoc, show

N = 12
y = esc_per_vert['vertical']
x = esc_per_vert['perc_churned']

source = ColumnDataSource(dict(y=y, right=x,))

xdr = DataRange1d()
ydr = DataRange1d()

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)

glyph = HBar(y="y", right="right", left=0, height=0.5, fill_color="#b3de69")
plot.add_glyph(source, glyph)

xaxis = LinearAxis()
plot.add_layout(xaxis, 'below')

yaxis = LinearAxis()
plot.add_layout(yaxis, 'left')

plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

curdoc().add_root(plot)

show(plot)

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/fa21388d-bbca-4a43-bdfa-075a0b7e092c%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.