2017-09-03 68 views
0

我已經生成了一個類似於該示例的holoviews \ Bokehheatmap graph
我在plot_optscolorbar=True中添加了一個顏色條,但顏色條的標籤以科學數字形式出現。
如何控制標籤的格式? 我試圖實現下面的代碼沒有成功:如何在散景中格式化彩條標籤

cbf = PrintfTickFormatter(format='0,0') 
color_bar = ColorBar(formatter=cbf) 

然後將其添加到plot_opts但它並沒有改變任何東西。

我看着這個user guide documentation和這個model documentation,但沒有設法弄清楚如何實現該屬性。

UPDATE
這是完整的代碼,但仍然無法正常工作。

dfqudf.head() 

| INDEX | dow | 小時 | QUERYTYPE |
| ------- | ------- | -------- | ------------- |
| 72 |週日| 0 | 205104 |
| 24 |週一| 0 | 210293 |
| 120 |週二| 0 | 206381 |
| 144 |週三| 0 | 212874 |
| 96 |週四| 0 | 216195 |

hv.extension('bokeh') 
colors = ["#75968f", "#a5bab7", "#c9d9d3", "#e2e2e2", "#dfccce", "#ddb7b1", "#cc7878", "#933b41", "#550b1d"] 
heatmap = hv.HeatMap(data=dfqudf[['hour','dow','QUERYTYPE']] 
        , label="Query Hour by Weekday") 

hover = HoverTool(tooltips=[('Num of Queries', '@QUERYTYPE{0,0}')]) 

formatter = NumeralTickFormatter(format='0,0') #PrintfTickFormatter(format='%.1f') doesn't work either 
color_bar = {'formatter': formatter} 
plot_opts = dict(width=900, height=300, xrotation=45, xaxis='top', labelled=[] 
       , tools=[hover], toolbar='below' 
       , colorbar=True, colorbar_opts= color_bar 
       ) 
style = dict(cmap=ListedColormap(colors)) 

heatmap(plot=plot_opts, style=style) 

回答

2

使用hv.help(element)您可以找出您可以使用什麼選項自定義元素。支持色彩映射的元素(包括HeatMap)接受通過ColorBar構造函數傳遞的colorbar_opts plot選項。這裏是一個非常簡單的例子:

from bokeh.models import PrintfTickFormatter 
formatter = PrintfTickFormatter(format='%.1f') 
plot_opts = dict(colorbar=True, colorbar_opts={'formatter': formatter}) 
hv.HeatMap([(0,0,0), (1,1,1)]).opts(plot=plot_opts) 
+0

THX使用'PrintfTickFormatter'和'NumeralTickFormatter'但在這兩種情況下,號碼的格式並沒有改變方向 –

+0

我試過了。有任何想法嗎? –

+0

記住你正在嘗試的東西,因爲上面的例子對我來說工作得很好。 – philippjfr