Reputation: 315
Good day,
I have the following colorbar for my Bokeh chart.
My code for the colorbar is as follows:
palette = brewer['Greys'][8]
palette = palette[::-1]
formatter = PrintfTickFormatter(format='%1.0f')
color_mapper = LinearColorMapper(palette = palette, low = 0, nan_color = '#d9d9d9')
color_bar = ColorBar(color_mapper=color_mapper, label_standoff=8,width = 500, height = 20,
border_line_color=None,location = (0,0), orientation = 'horizontal', formatter = formatter)
I would like to make a couple of changes and was wondering if anyone can assist me with any of the following:
Thank you to anyone who can assist me! Have a great day.
Upvotes: 1
Views: 1273
Reputation: 6367
Here is a collection:
ColorBar
has a bar_line_color
. Default is None
. Set this to your favorite color (like "black"
)ColorBar
has a ticker
and you can set this to BasicTicker(desired_num_ticks=len(palette)+1)
.NumeralTickFormatter
with the format (0.00 a)
to display numbes i the wanted formatSee the example below:
from bokeh.palettes import brewer
from bokeh.transform import transform
from bokeh.models import NumeralTickFormatter ,LinearColorMapper, ColorBar, BasicTicker, ColumnDataSource
from bokeh.plotting import figure, show, output_notebook
output_notebook()
source = ColumnDataSource(dict(
x=[1,10,100,200,400,1000,2000,4000],
y=[1,2,3,4,5,6,7,8]
))
palette = brewer['Greys'][8][::-1]
p = figure(width=500, height=300)
color_mapper = LinearColorMapper(palette = palette, low = 0, nan_color = '#d9d9d9')
p.circle('x', 'y', color=transform("x", color_mapper), line_color='black', size=10, source=source)
color_bar = ColorBar(
color_mapper=color_mapper,
label_standoff=8,
width = 425,
height = 20,
location = (0,0),
orientation = 'horizontal',
formatter = NumeralTickFormatter(format='0.00 a'),
ticker=BasicTicker(desired_num_ticks=len(palette)+1),
bar_line_color='black',
major_tick_line_color='black'
)
p.add_layout(color_bar, 'below')
show(p)
Upvotes: 1