我有一个矩阵,我用它画出下面的图.
正如人们所看到的那样,绘图的总行和列部分主导着 colored颜色 比例,这反过来又削弱了其他值的视觉效果.我的目标是删除最后一行和最后一列的色阶,但我不确定该怎么做.
这是我当前的绘图代码
def annotate_matrix_values(df: pd.DataFrame, fig: go.Figure) -> go.Figure:
df_matrix = df.to_records(index=False)
for i, r in enumerate(df_matrix):
for k, c in enumerate(r):
fig.add_annotation(
x=k,
y=i,
text=f"<b>{str(int(c))}</b>" if not math.isnan(c) else "",
showarrow=False,
)
fig.update_xaxes(side="top")
fig.update_coloraxes(showscale=False)
return fig
df_final = pd.crosstab(pt[y_axis_name], pt[x_axis_name], margins=True)
fig = px.imshow(
df_final,
labels=dict(x=x_title, y=y_title, color="Value"),
x=x_label,
y=y_label,
color_continuous_scale="Purples",
aspect="auto",
)
fig = annotate_matrix_values(df_final, fig)
当然,我可以在这里设置边距为false,得到下面的图.但是我不能显示总数.
df_final = pd.crosstab(pt[y_axis_name], pt[x_axis_name], margins=False)
所以我的目标是显示总数,但不显示任何色阶.谢谢你的帮助