簡體   English   中英

如何讓散景圖上的顏色與正確的值(對數刻度)對齊?

[英]How do I get colors on a bokeh plot to line up with their correct values (log scale)?

我的問題類似於這個討論 - 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)

當這個情節出現時,我會得到類似這個屏幕截圖的東西

使用懸停工具將鼠標懸停在點上(對不起,我不知道如何嵌入/鏈接散景圖)......您會看到圖中的顏色不適合點值。 我在這里缺少什么?

user11705556 指出,這個問題是通過在 logcolorbar 之間進行 log 轉換來解決的,該 log 轉換與 fill_color 的 log 轉換不同,cf the PR

(在 user11705556 發布她自己問題的答案后,我將刪除此答案。)

這是 Bokeh 1.4 中的一個問題,但已在 master 上解決,並將在即將發布的 2.0 版本中解決。 原始代碼在 2.0 "dev" 版本中按預期運行。

這是答案

我發現了這個問題並設法解決了這個問題。 看到這個線程:

它本質上與 logcolorbar 之間的 log 轉換與 fill_color 的 log 轉換不同,這會導致 0 和 1 之間的值(我的域)出現問題。 在此處查看我的帖子:github.com/bokeh/bokeh/pull/8832

顯然,這將在下一個版本中得到解決,但與此同時,我的解決方法可以解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM