11

LS, Bokeh plot automatically generates a legend for a plot. How can I hide (not show at all) the legend in a Bokeh plot ? I tried: legend = 'none'. But no success. Thanks

ArtDijk
  • 1,957
  • 6
  • 23
  • 31

2 Answers2

10

If I can just expand this a little - legend=False is the correct way to make the Bokeh legend invisible, but it's used within the creation of the plot itself, rather than being called as an attribute of the plot object. By which I mean, write

from bokeh.charts import Scatter
myPlot = Scatter(foo, bar, legend=False)

rather than

from bokeh.charts import Scatter
myPlot = Scatter(foo, bar)
myPlot.legend=False.
amunnelly
  • 1,144
  • 13
  • 22
  • 7
    In Bokeh 0.12.5 this does not work anymore. Use instead `myPlot.legend.visible = False`. – paljenczy May 24 '17 at 14:51
  • 2
    Note that you should specify `myPlot.legend.visible = False` only after you add all the glyphs to the plot, because adding a glyph with arg like `legend='something'` will set legend to visible again. – dux2 Dec 17 '18 at 08:27
  • 1
    In Bokeh 2.2.1: `myplot.legend.visible = False` makes the legend invisible, but **I am still able to interact with the invisible legend**! This is a problem when I use the hover tooltip: when I mouse over the invisible legend, I lose my tooltip and get the pointing-finger icon instead. Is there a setting that *completely* removes the legend? – Mike Gazes Nov 17 '20 at 16:25
2
p1.line(x=data['col'].astype(str), y=data['col'],
     color='black',legend_label='legend')
p1.legend.visible=False 

The last line hides the legend.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Joselin Ceron
  • 474
  • 5
  • 3