2016-10-15 2 views
3

私はLinearColorMapperインスタンスに連続した値をマッピングしHeatMapのこのスタイルを再現しようとしていた。http://bokeh.pydata.org/en/latest/docs/gallery/unemployment.html 私はHeatMap(どちらかのw/chartsまたはrect)にしたかったし、その後obsv_idを選択するために、single selection widgetを追加し、slider widgetdatesにアクセスしてください。Python 3を使って連続カラーマップで `Bokeh`の` Heatmaps`を作る方法は?

しかし、HeatMap自体が1つのobsv_id/dateというペアで問題を抱えていました。これを作成する際に間違っていることは何ですか?HeatMap?これは基本的にsize変数とloc変数の3x3矩形プロットです。

ボーナス:これらのウィジェットの出力をワイヤリングしてプロットを制御する方法を教えてください。

私はこれらの記事を見ましたが、全ての実施例は、連続測定を使用して代わりに、マッピングのリストとして実際の六角色を使用します。 python bokeh, how to make a correlation plot?http://bokeh.pydata.org/en/latest/docs/gallery/categorical.html

# Init 
import numpy as np 
import pandas as pd 
from bokeh.plotting import figure, output_notebook, output_file, reset_output, show, ColumnDataSource 
from bokeh.models import LinearColorMapper 
reset_output() 
output_notebook() 

np.random.seed(0) 

# Coords 
dates = ["07-3","07-11","08-6","08-28"] 
#locs = ["air","water","earth"] 
locs = [0,1,2] 
size = [3.0, 0.2, 0.025] 
observations = ["obsv_%d"%_ for _ in range(10)] 


# Data 
Ar_tmp = np.zeros((len(dates)*len(locs)*len(size)*len(observations), 5), dtype=object) 

i = 0 
for date in dates: 
    for loc in locs: 
     for s in size: 
      for obsv_id in observations: 
       Ar_tmp[i,:] = np.array([obsv_id, date, loc, s, np.random.random()]) 
       i += 1 
DF_tmp = pd.DataFrame(Ar_tmp, columns=["obsv_id", "date", "loc", "size", "value"]) 
DF_tmp["value"] = DF_tmp["value"].astype(float) 
DF_tmp["size"] = DF_tmp["size"].astype(float) 
DF_tmp["loc"] = DF_tmp["loc"].astype(float) 
#  obsv_id date loc size  value 
# 0 obsv_0 07-3 air 3.0 0.548814 
# 1 obsv_1 07-3 air 3.0 0.715189 
# 2 obsv_2 07-3 air 3.0 0.602763 
# 3 obsv_3 07-3 air 3.0 0.544883 
# 4 obsv_4 07-3 air 3.0 0.423655 

mapper = LinearColorMapper(low = DF_tmp["value"].min(), high = DF_tmp["value"].max()) 

# # Create Heatmap of a single observation and date pair 
query_idx = set(DF_tmp.index[DF_tmp["obsv_id"] == "obsv_0"]) & set(DF_tmp.index[DF_tmp["date"] == "08-28"]) 

# p = HeatMap(data=DF_tmp.loc[query_idx,:], x="loc", y="size", values="value") 
p = figure() 
p.rect(x="loc", y="size", 
     source=ColumnDataSource(DF_tmp.loc[query_idx,:]), 
     fill_color={'field': 'value', 'transform': mapper}, 
     line_color=None) 
show(p) 

マイエラー:

# Javascript error adding output! 
# TypeError: Cannot read property 'length' of null 
# See your browser Javascript console for more details. 

答えて

1

あなたは持っていますpaletteLinearColorMapperを提供する。 LinearColorMapper docから

mapper = LinearColorMapper(
    palette='Magma256', 
    low=DF_tmp["value"].min(), 
    high=DF_tmp["value"].max() 
) 

:たとえば

class LinearColorMapper(palette=None, **kwargs) 

Map numbers in a range [low, high] linearly into a sequence of colors (a palette).


なく、あなたの例外に関連していますが、p.rect()widthheightパラメータを渡す必要があります。

関連する問題