python - 如何让散景图上的颜色与其正确值(对数刻度)对齐?
问题描述
我的问题与此讨论类似-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)
当这个情节出现时,我得到了类似这样的 屏幕截图
使用悬停工具将鼠标悬停在点上(对不起,我不知道如何嵌入/链接散景图)...您会看到图上的颜色不适合点值。我在这里想念什么?
解决方案
这是答案
我发现了问题并设法解决了问题。看到这个线程:
它本质上与 logcolorbar 之间的对数转换与 fill_color 的对数转换不同有关,这会导致 0 和 1 之间的值(我的域)出现问题。在这里查看我的帖子:github.com/bokeh/bokeh/pull/8832
显然这将在下一个版本中解决,但同时我的解决方法会做。
推荐阅读
- android-studio - 在真实设备上测试 android 应用程序时如何显示日志?
- vba - 我在 VBA 中使用过滤器命令时遇到语法错误问题
- r - 在R语言中将字符串转换为时间格式
- python - Python条件使用正则表达式和多行字符串
- kubernetes - 当 kube-proxy 无法到达 master 时,它的行为如何?
- advanced-custom-fields - 高级自定义字段帖子磁贴和图像 url
- azure-devops - 如何获取(重新创建)AzureDevOps Pipelines 中使用的不记名令牌?
- aws-api-gateway - 使用无服务器设置 aws api 网关
- react-native - Firebase 的电话和谷歌身份验证
- java - 选择属性 ID 范围内的所有元素并返回特定元素