【问题标题】:How do I get colors on a bokeh plot to line up with their correct values (log scale)?如何让散景图上的颜色与它们的正确值(对数刻度)对齐?
【发布时间】:2020-01-06 22:49:59
【问题描述】:

我的问题与这个讨论类似-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)

当这种情况发生时,我会得到这样的东西 screencap

使用悬停工具将鼠标悬停在点上(抱歉,我不知道如何嵌入/链接散景图)...您会发现图上的颜色不适合点值。我在这里错过了什么?

【问题讨论】:

  • 好吧,我想出了一个解决方法。它本质上与 logcolorbar 之间的 log 变换与 fill_color 的 log 变换不同有关,这会导致 0 和 1 之间的值(我的域)出现问题。在这里查看我的帖子:github.com/bokeh/bokeh/pull/8832

标签: python python-3.x bokeh


【解决方案1】:

user11705556 指出这个问题可以通过执行 logcolorbar 之间的对数转换与 fill_color 的对数转换不同, 参考the PR

(在 user11705556 发布她自己的问题的答案后,我将删除此答案。)

【讨论】:

    【解决方案2】:

    这是 Bokeh 1.4 中的一个问题,但已在 master 上解决,并将在即将发布的 2.0 版本中解决。原始代码在 2.0“开发”版本中按预期运行。

    【讨论】:

      【解决方案3】:

      这就是答案

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

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

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

      【讨论】:

        猜你喜欢
        • 2017-01-22
        • 1970-01-01
        • 2021-07-13
        • 2019-12-23
        • 1970-01-01
        • 2013-02-21
        • 2023-01-09
        • 1970-01-01
        • 2019-02-25
        相关资源
        最近更新 更多