Hide legend in bokeh plot

10,103

Solution 1

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.

Solution 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.

Share:
10,103
ArtDijk
Author by

ArtDijk

Updated on July 10, 2022

Comments

  • ArtDijk
    ArtDijk almost 2 years

    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

  • paljenczy
    paljenczy almost 7 years
    In Bokeh 0.12.5 this does not work anymore. Use instead myPlot.legend.visible = False.
  • dux2
    dux2 over 5 years
    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.
  • Mike Gazes
    Mike Gazes over 3 years
    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?