gwaldman13
gwaldman13

Reputation: 121

Change bar width with a python Bokeh grouped bar chart?

Here is an example. No matter what I can bar_width too, the figure looks exactly the same. How can I increase the widths of all the bars?

from bokeh.charts import Bar, output_notebook, show, vplot, hplot, defaults
from bokeh.sampledata.autompg import autompg as df
output_notebook()

df['neg_mpg'] = 0 - df['mpg']

defaults.width = 550
defaults.height = 400
bar_plot7 = Bar(df, label='cyl', values='displ', agg='mean', group='origin', bar_width=10,
                title="label='cyl' values='displ' agg='mean' group='origin'", legend='top_right')
show(bar_plot7)

Upvotes: 2

Views: 1607

Answers (2)

George Pamfilis
George Pamfilis

Reputation: 1487

from bokeh.charts import Bar
from bokeh.charts.attributes import ColorAttr, CatAttr
from bokeh.charts.builders.bar_builder import BarBuilder

# output_file('try_select.html')
data = pd.DataFrame({'labels':['b', 'a', 'd', 'c'], 'values': [1, 2, 3, 4]}, index=[1, 2, 3, 4])
plt = Bar(data, values='values',label=CatAttr(columns=['labels'], sort=False),color=ColorAttr(columns=['labels']))
output_notebook()
show(plt)

this will work if you modify the df to your groupby df.

Upvotes: 0

Randy
Randy

Reputation: 14847

Looks like a bug in the new version of Bokeh where the widths are not making it all the way to the end. For now, you can do something like:

for r in bar_plot7.renderers:
    try:
        r.glyph.width = 0.1
    except AttributeError:
        pass

before the show() call to make skinny bars.

Upvotes: 6

Related Questions