简体   繁体   English

如何使用散景创建比例(预定义边界)彩条?

[英]How to create a proportional (pre-defined boundaries) colour bar with bokeh?

I would like to plot a graph with a proportional colour bar on the right like graph 1, but with bokeh rather than matplotlib.我想 plot 一个图形,右侧有一个比例颜色条,如图 1 所示,但使用散景而不是 matplotlib。

Here's the matplotlib version with a proportional (pre-defined boundaries) colour bar using matplotlib colors.BoundaryNorm(bounds, cmap.N) :这是使用matplotlib colors.BoundaryNorm(bounds, cmap.N)的比例(预定义边界)彩条的 matplotlib 版本:

matplotlib 版本

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.我正在使用散景,因为它适用于 Django 并且它在散景库中具有工具选项。

Please give suggestions.请提出建议。 Thanks in advance,提前致谢,

I have got an answer from discourse.bokeh.org Community Suppor.我从 discourse.bokeh.org 社区支持得到了答案。 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. Bokeh 1.3.4 只有线性和对数颜色映射器。 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.这样做的方法是创建一个包含 100 个条目的更大的调色板,它隐含地提供了你想要的“中断”。 Eg例如

palette = [ "yellow" ]*5 + ["pink"]*20 + ["red"]*50 +...调色板 = [“黄色”]*5 + [“粉色”]*20 + [“红色”]*50 +...

Then this palette could be used with a LinearColorMapper with low, high = (0, 100).然后这个调色板可以与具有低、高 = (0, 100) 的 LinearColorMapper 一起使用。

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.请随时提出GitHub 问题来讨论它。

so, the updated graph is here, happy!所以,更新的图表就在这里,快乐! 更新的图表在这里,快乐! ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM