How to stick Legend outside Bar plot

Hi,

How can I move the Legend outside the diagram in a Bar plot? I am using this example:

from bokeh.charts import Bar, output_file, show
from bokeh.layouts import row

# best support is with data in a format that is table-like
data = {
    'sample': ['1st', '2nd', '1st', '2nd', '1st', '2nd'],
    'interpreter': ['python', 'python', 'pypy', 'pypy', 'jython', 'jython'],
    'timing': [-2, 5, 12, 40, 22, 30]
}

# x-axis labels pulled from the interpreter column, stacking labels from sample column
bar = Bar(data, values='timing', label='interpreter', stack='sample', agg='mean',
          title="Python Interpreter Sampling", legend='top_right', plot_width=400)

# table-like data results in reconfiguration of the chart with no data manipulation
bar2 = Bar(data, values='timing', label=['interpreter', 'sample'],
           agg='mean', title="Python Interpreters", plot_width=400)

output_file("stacked_bar.html")
show(row(bar, bar2))

The idea is to avoid overlapping the bars with the legends

Best,

Daniel.

<img src="//bokeh-discourse-uploads.s3.dualstack.us-east-1.amazonaws.com/original/1X/f7aa947ef961af7aa46777ec6ea47a480c7f59d5.png" alt="">

I'm ont sure this is possible (or at least not very easily possible) with bokeh.charts.Bar. For now, I'd encourage you to look at the new vbar and hbar glyphs added to bokeh.plotting:

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

This is slightly more verbose, but will give you much better explicit control over things like legends, you can use the technique here:

  Appearance — Bokeh 3.3.2 Documentation

To get a legend outside the plotting area with bokeh.plotting

Thanks,

Bryan

···

On Sep 21, 2016, at 10:13 AM, [email protected] wrote:

Hi,

How can I move the Legend outside the diagram in a Bar plot? I am using this example:

from bokeh.charts import Bar, output_file, show
from bokeh.layouts import row

# best support is with data in a format that is table-like
data = {

'sample': ['1st', '2nd', '1st', '2nd', '1st', '2nd'],

'interpreter': ['python', 'python', 'pypy', 'pypy', 'jython', 'jython'],

'timing': [-2, 5, 12, 40, 22, 30]
}

# x-axis labels pulled from the interpreter column, stacking labels from sample column
bar = Bar(data, values='timing', label='interpreter', stack='sample', agg='mean',

title="Python Interpreter Sampling", legend='top_right', plot_width=400)

# table-like data results in reconfiguration of the chart with no data manipulation
bar2 = Bar(data, values='timing', label=['interpreter', 'sample'],

agg='mean', title="Python Interpreters", plot_width=400)

output_file("stacked_bar.html")
show(row(bar, bar2))

The idea is to avoid overlapping the bars with the legends

Best,

Daniel.

<Auto Generated Inline Image 1.png>

--
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/4a06a3be-aa25-482a-b312-114eb14846d2%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
<Auto Generated Inline Image 1.png>