我需要复制那个热图。
我有一个数据框,它的两列是
"overall"
和"potential"
。热图需要显示潜力与整体。我需要按照这个草图来获得图表:
#Create a matrix filled with zeros and dimension 100x100
matrix = np.zeros((100,100))
limit_matrix = np.zeros((100,100))
for ov,pot in zip(df['overall'],df['potential']):
# Increase the value in the matrix in ov row and the pot column by 1
matrix[ov,pot]+=1
color_limits=[0,1,5,20,50,100]
# Iterate over ov grid
for ov in range(100):
# Iterate over pot grid
for pot in range(100):
group_index = [v for v,value in enumerate(color_limits) if value<=matrix[ov,pot]][-1]
# Store the group index to limit matrix
# Create the figure
# Save the figure
这是我到目前为止的尝试:
#Create a matrix filled with zeros and dimension 100x100
matrix = np.zeros((100,100))
limit_matrix = np.zeros((100,100))
for ov,pot in zip(df['overall'],df['potential']):
# Increase the value in the matrix in ov row and the pot column by 1
matrix[ov,pot]+=1
color_limits=[0,1,5,20,50,100]
# Iterate over ov grid
for ov in range(100):
# Iterate over pot grid
for pot in range(100):
group_index = [v for v,value in enumerate(color_limits) if value<=matrix[ov,pot]][-1]
# Store the group index to limit matrix
limit_matrix[ov, pot] = group_index
fig = go.Figure(data=go.Heatmap(
z=matrix,
zmin=0,
zmax=100,
colorbar=dict(
tickvals=color_limits,
ticktext=color_limits,
title='Count greater than'
)
))
fig
我的问题是我不知道如何使用图形描述中的矩阵
"limit_matrix"
。另外,我得到了我应该得到的反映版本。
非常感谢任何提示或帮助。谢谢。