从绘图 imshow / 热图的最后一行和最后一列中删除色标
我有一个矩阵,用它来绘制以下图。
正如人们所看到的,绘图的总行和列部分主导了色阶,这反过来又削弱了其他值的视觉效果。我的目标是删除最后一行和最后一列的色阶,但我不确定如何做到这一点。
这是我当前的绘图代码
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)
当然我可以在这里设置 margin false 并得到以下绘图。但我无法显示总数。
df_final = pd.crosstab(pt[y_axis_name], pt[x_axis_name], margins=False)
所以我的目标是显示总数,但上面没有任何色标。感谢您的帮助
I have a matrix with which i am plotting the following plot.
As one could see the total row and column part of the plot dominates the colorscale which in turn diminishes the visual effect of other values. My goal is to remove the color scale from last row and column but i am unsure how to do it.
Here is my current plot code
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)
Of course i can set margin false here and get the following plot. But then I cant show the totals.
df_final = pd.crosstab(pt[y_axis_name], pt[x_axis_name], margins=False)
So my goal is to show the totals but without any color scale on it. Thanks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
了解问题的目的是从色标中排除总数后,我尝试了使用子图并覆盖空白图表和热图的各种方法,但没有得到好的结果。最简单的方法是向 EXPRESS 热图添加四边形和注释。数据以带有分类变量的 x,y 形式创建。热图是使用不包括总计的数据创建的,并且注释是使用总计作为字符串创建的。
With the understanding that the purpose of the question was to exclude totals from the color scale, I tried various approaches with subplots and overlaying a blank graph and heatmap, but did not get good results. The simplest approach was to add a quadrangle and annotation to the EXPRESS heatmap. The data was created in the form of x,y with categorical variables. The heatmap was created with data not including totals, and the annotations were created with the totals as strings.