Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

bokeh

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)
like image 720
petezurich Avatar asked Nov 25 '25 08:11

petezurich


1 Answers

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.

like image 142
bigreddot Avatar answered Nov 26 '25 21:11

bigreddot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!