Search code examples
pythonbokeh

How to set the legend color's transparency in Bokeh independently from fill_alpha of scatter plot?


For a complex scatterplot with 20k+ points I need to set the fill_alpha of the scatter points to a low value, say 0.2.

How can I set the fill color in the legend to full opaque (aka not transparent)?

enter image description here

Example code:

from bokeh.plotting import figure, output_file, show
from bokeh.models import ColumnDataSource

p = figure(plot_width=640, plot_height=320)

x = [10]
y = [10]
color = ["blue"]
category = ["Lorem Ipsum"]

source = ColumnDataSource(dict(x = x, y = y, color=color, legsrc=category))

p.scatter(x="x", y="x", fill_alpha=.2, size=100, color="color",
         line_color=None, marker="circle", source=source, legend="legsrc")

show(p)

Solution

  • As of Bokeh 1.0.2. this is not possible. Legend items always mirror the visual properties of the glyph they represent exactly, including alpha. If you would like to discuss the possibility of adding some mechanism to override legend glyph properties, the next step would be to make a detailed feature request issue on GitHub.