Altair:无法通过多面热图获得独立的“ y”比例

时间:2019-09-26 18:05:54

标签: heatmap facet altair

我正在使用一个Jupyter笔记本工作,试图使用Altair的Chart.facet()方法以一种类似this one的分组布局显示一种类似邻接矩阵的数据集。 This guy's answer可以将我带到一半,但是当我尝试对行进行分面并将y比例解析为“独立”时,图表将显示为a tiny box containing no elements

df = (pd.util.testing.makeDataFrame()
      .reset_index(drop=True)  # drop string index
      .reset_index()  # add an index column
      .melt(id_vars=['index'], var_name="column")
     )

# To include all the indices and not create NaNs, I add -1 and max(indices) + 1 to the desired bins.
hbins= [-1, 3, 9, 15, 27, 30]
df['hbins'] = pd.cut(df['index'], hbins, labels=range(len(hbins) - 1))
# This was done for the index, but a similar approach could be taken for the columns as well.

df['vbins'] = df.column.replace({'A':'Grp1', 'B':'Grp1', 'C':'Grp2', 'D':'Grp2'})

alt.Chart(df).mark_rect().encode(
    x=alt.X('index:O', title=None),
    y=alt.Y('column:O', title=None),
    color="value:Q",
    column=alt.Column("hbins:O", 
                      title=None, 
                      header=alt.Header(labelFontSize=0)
                     ),
    row=alt.Row("vbins:O", 
                      title=None, 
                      header=alt.Header(labelFontSize=0)
                     )
).resolve_scale(
    x="independent",
    y="independent"
).configure_facet(
    spacing=5
)

可能是什么原因造成的?

0 个答案:

没有答案