问题
I would like to plot a graph with a proportional colour bar on the right like graph 1, but with bokeh rather than matplotlib.
Here's the matplotlib version with a proportional (pre-defined boundaries) colour bar using matplotlib colors.BoundaryNorm(bounds, cmap.N)
:

But my current bokeh version has the right hand side colour bar not proportional, although I have given ticker boundaries:

My bokeh code:
ticker = FixedTicker(ticks=bounds)
bounds = [0, 5, 25, 75, 95,100]
color_bar = ColorBar(color_mapper=mapper, major_label_text_font_size='5pt',
ticker=ticker,
formatter=PrintfTickFormatter(format='%d%%'),
label_standoff=6, border_line_color=None, location=(0, 0))
I'm using bokeh as it works well with Django and it has the tools option within the bokeh library.
Please give suggestions. Thanks in advance,
回答1:
I have got an answer from discourse.bokeh.org Community Suppor. There is a way but build a new feature would be even better. The answer is here:
Bokeh 1.3.4 only has linear and log colour mappers. There is no built-in notion of a “segmented” colour mapper. On way to do it is by creating a larger palette with 100 entries, that provides the “breaks” you want implicitly. E.g.
palette = [ "yellow" ]*5 + ["pink"]*20 + ["red"]*50 + ...
Then this palette could be used with a LinearColorMapper with low, high = (0, 100).
A segmented colour mapper would be a reasonable ask for a new feature, and also an excellent self-contained task for a new contributor. Please feel free to make a GitHub issue to discuss it.
so, the updated graph is here, happy!
来源:https://stackoverflow.com/questions/58159110/how-to-create-a-proportional-pre-defined-boundaries-colour-bar-with-bokeh