首页 > 解决方案 > 如何让散景图上的颜色与其正确值(对数刻度)对齐?

问题描述

我的问题与此讨论类似-https ://github.com/bokeh/bokeh/issues/5020

我正在尝试使用对数比例着色方案对散景图上的点进行主题化,并有一个与之配套的颜色条。我的“颜色值”(即我的主题范围从 1e-9 到 1e-3)。

我现在的问题是,我可以使用 LogColorMapper 和 LogTicker 使颜色条适当地适应定义的颜色范围,但是在我的点上的 fill_color 属性上使用相同的 LogColorMapper 似乎映射不正确。请参阅下面的最小化示例:

import numpy as np
from bokeh.io import show
from bokeh.models import ColorBar, LogTicker,Ticker,HoverTool
from bokeh.models.sources import ColumnDataSource
from bokeh.models.mappers import LinearColorMapper, LogColorMapper
from bokeh.palettes import Viridis6, Viridis3,Spectral11
from bokeh.plotting import figure

x = np.linspace(0, 1000, num=1000)
y = [np.random.random()*1000 for x in range(0,1000)]
#generate a random lognormal list, median 1e-6 with standard deviation of 1 order of magnitude
z = 10**np.random.normal(-6, 1, size=1000)

source = ColumnDataSource(dict(x=x, y=y, z=z))

log_mapper = LogColorMapper(palette=Viridis6, low=1e-9, high=1e-3)

custom_hover = HoverTool()
custom_hover.tooltips=[('Value','@z'),]

p = figure(x_axis_type='linear', toolbar_location='above',tools=[custom_hover])
opts = dict(x='x', line_color=None, source=source)
p.circle(y='y', fill_color={'field': 'z', 'transform': log_mapper}, legend="Log mapper", **opts)

colorbar = ColorBar(color_mapper=log_mapper,ticker=LogTicker(), location=(0,0), orientation='horizontal', padding=0)

p.add_layout(colorbar, 'below')

show(p)

当这个情节出现时,我得到了类似这样的 屏幕截图

使用悬停工具将鼠标悬停在点上(对不起,我不知道如何嵌入/链接散景图)...您会看到图上的颜色不适合点值。我在这里想念什么?

标签: pythonpython-3.xbokeh

解决方案


这是答案

我发现了问题并设法解决了问题。看到这个线程:

它本质上与 logcolorbar 之间的对数转换与 fill_color 的对数转换不同有关,这会导致 0 和 1 之间的值(我的域)出现问题。在这里查看我的帖子:github.com/bokeh/bokeh/pull/8832

显然这将在下一个版本中解决,但同时我的解决方法会做。


推荐阅读