heatmap - Altair:无法使用多面热图获得独立的“y”比例
问题描述
我正在一个 jupyter 笔记本中工作,试图使用 Altair 的方法在像这样的分组布局中显示一种类似邻接矩阵的数据集。这个人的回答让我走到了一半,但是当我尝试用行来分面并将 y 刻度解析为“独立”时,图表出现为一个不包含任何元素的小盒子。Chart.facet()
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
)
这可能是什么原因造成的?
解决方案
推荐阅读
- java - 使用 ELKI 的 dbscan 可视化结果
- python - 如果列表中的子字符串//pythonic方式,python替换字符串中的子字符串
- laravel - 如何使用不同的数据库名称使用默认的 laravel 身份验证更改?
- c++ - 具有多种可行类型的模板重载解决方案
- java - Int 不能转换为二进制字符串
- javascript - 如何将三个功能合并为一个功能以执行相同的功能?
- python - 我无法使用 pip3 install Jinja 在 Pycharm 中安装 Jinja。如何解决这个错误?
- ssis - SSIS 在另一台服务器上执行
- python - 使用 OpenCV 和 Python 将一个圆分成 12 个相等的部分
- python - 当 python 数据框的数据没有变化时,用平均值修复历史数据