调整holoviews散景中的颜色图以匹配值的分布 [英] Adjust colormap in holoviews bokeh to match distribution of values

查看:129
本文介绍了调整holoviews散景中的颜色图以匹配值的分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下选项在具有bokeh扩展名的jupyter笔记本中的Holoviews中创建了一个地图:

I have created a map in Holoviews in jupyter notebook with the bokeh extension using the following options:

%output size=150
%opts Overlay [show_legend=True, width=800 height=400]
%opts Points.Data [color_index='b' size_index='a' scaling_factor=10 colorbar=True](cmap='RdYlGn' size=3)

'b'和'a'都是介于-1之间的变量和1。

Both 'b' and 'a' are variables ranging between -1 and 1.

这会产生两个问题(也比较图片):

This produces two issues (also compare picture):


  1. 根据变量'a'的绝对值确定点的大小。但是,我希望值产生的值越小(越大),则负值(正)越多。有什么解决方法(除了在绘制前将 a缩放到正范围外)?

  2. 由于 b的正值明显多于负值,几乎所有点都被映射变为绿色,而很少使用颜色范围的负数部分。我不想转换 b,因为它的含义很有意义,我希望在颜色图例中显示该值。关于如何调整颜色图以更好地反映'b'值的分布的任何建议?

  1. the points are sized according to the absolute value of variable 'a'. However, I'd like values to produce smaller (larger) points the more negative (positive) the value. Any solution to that (except for rescaling 'a' to a positive range before plotting)?
  2. As there are significantly more positive values of 'b' than negative ones, almost all points a mapped to green color while the negative part of the color range gets very rarely used. I don't want to transform 'b', as there is meaning to its value which I would like to be displayed in the color legend. Any suggestions how to adjust the color map to reflect the distribution of 'b' values better?

我对holoviews / bokeh和尚未习惯语法。因此,我也会感谢示例代码。

I am new to holoviews/bokeh and not yet used to the syntax. Therefore I'd appreciate sample code as well.

推荐答案

要回答#2,您可以从默认颜色图制作自己的颜色图,然后从颜色图的末端删除许多颜色(更改开始/停止),如下所示

To answer #2, you could make your own color map from a default color map and remove however many colors from the ends of the color map (changing start/stop) like this

from matplotlib.colors import LinearSegmentedColormap
import matplotlib.pyplot as plt
cmap_name = 'RdBu_r'
start = 0.4
stop = 1
n = 256
cmap = plt.get_cmap(cmap_name)
colors = cmap(np.linspace(start, stop, cmap.N))
new_cmap = LinearSegmentedColormap.from_list('mycmap', colors=colors, N=n)

然后执行 points = points.redim.range(data =(-0.2,1))

例如,在下面,我从RdBu_r中切出所有蓝色,只留下红色
https://holoext.readthedocs.io/en/latest/ examples / changing_colorbar_cmap.html#Colorbar-string-shortcut

As an example, below, I cut out all the blues from RdBu_r, leaving only reds https://holoext.readthedocs.io/en/latest/examples/changing_colorbar_cmap.html#Colorbar-string-shortcut

这篇关于调整holoviews散景中的颜色图以匹配值的分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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