【发布时间】:2022-01-14 20:48:26
【问题描述】:
我只想显示此热图“Total Wins”的一列,因此它将是第一个垂直列。我希望该图仍然是一个具有图例且具有交互性的绘图对象。
'''
import plotly.figure_factory as ff
import plotly.graph_objects as go
import numpy as np
corr = new_best_teams.corr()
corr = round(corr,3)
mask = np.triu(np.ones_like(corr, dtype=bool))
new_best_teams_mask = corr.mask(mask)
fig = ff.create_annotated_heatmap(z=new_best_teams_mask.to_numpy(),
x=new_best_teams_mask.columns.tolist(),
y=new_best_teams_mask.columns.tolist(),
colorscale=px.colors.diverging.RdBu,
hoverinfo="none",
showscale=True, ygap=1, xgap=1
)
fig.update_xaxes(side="bottom")
fig.update_layout(
title_text='Heatmap',
title_x=0.5,
width=1000,
height=1000,
xaxis_showgrid=False,
yaxis_showgrid=False,
xaxis_zeroline=False,
yaxis_zeroline=False,
yaxis_autorange='reversed',
template='plotly_white'
)
for i in range(len(fig.layout.annotations)):
if fig.layout.annotations[i].text == 'nan':
fig.layout.annotations[i].text = ""
fig.show()
'''
这是输出的图像:enter image description here
这是我想要的图像(我希望它仍然是包含图例的交互式绘图图):enter image description here
【问题讨论】:
-
难道不可以通过将数据限制为要输出的数据来做到这一点,而不是在图形端进行调整吗?