我可以为散景热图绘制颜色条吗? [英] Can I plot a colorbar for a bokeh heatmap?

查看:73
本文介绍了我可以为散景热图绘制颜色条吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景虚化是否有一种简单的方法来绘制热图的颜色栏?

在此示例中说明颜色如何与值相对应.

In this example it would be a strip illustrating how colors correspond to values.

在matlab中,它称为颜色栏",如下所示:

In matlab, its called a 'colorbar' and looks like this:

推荐答案

更新:现在,这容易得多:请参见

UPDATE: This is now much easier: see

http://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#color-bars

恐怕我没有很好的答案,这在Bokeh中应该更容易些.但是我以前手动做过类似的事情.

I'm afraid I don't have a great answer, this should be easier in Bokeh. But I have done something like this manually before.

因为我经常希望这些图形不在我的图上,所以我制作了一个新图,然后将其与hplotgridplot之类的东西组装在一起.

Because I often want these off my plot, I make a new plot, and then assemble it together with something like hplot or gridplot.

这里有一个示例: https ://github.com/birdsarah/pycon_2015_bokeh_talk/blob/master/washmap/washmap/water_map.py#L179

在您的情况下,情节应该很简单.如果您创建了这样的数据源:

In your case, the plot should be pretty straight forward. If you made a datasource like this:

| value | color
| 1     | blue
.....
| 9     | red

然后您可以执行以下操作:

Then you could do something like:

legend = figure(tools=None)
legend.toolbar_location=None
legend.rect(x=0.5, y='value', fill_color='color', width=1, height=1, source=source)
layout = hplot(main, legend)
show(legend)

但是,这确实取决于您知道值对应的颜色.您可以将调色板传递给您的热图图表调用-如下所示: http ://docs.bokeh.org/zh-CN/latest/docs/gallery/cat_heatmap_chart.html ,这样您便可以使用它来构造新的数据源.

However, this does rely on you knowing the colors that your values correspond to. You can pass a palette to your heatmap chart call - as shown here: http://docs.bokeh.org/en/latest/docs/gallery/cat_heatmap_chart.html so then you would be able to use that to construct the new data source from that.

我很确定在颜色图上至少有一个未解决的问题.我知道我刚刚为剧情传奇添加了一个.

I'm pretty sure there's at least one open issue around color maps. I know I just added one for off-plot legends.

这篇关于我可以为散景热图绘制颜色条吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆