我有一个使用此代码创建的热图:
dfreverse = df_hml.values.tolist()
dfreverse.reverse()
colorscale = [[0, '#FFFFFF'],[0.4, '#F8F8FF'], [1, '#F1C40F']]
x = [threeYr,twoYr,oneYr,Yr]
y = ['March', 'February', 'January', 'December', 'November', 'October', 'September', 'August', 'July', 'June', 'May', 'April']
z = dfreverse
z_text = np.around(z, decimals=2) # Only show rounded value (full value on hover)
fig = ff.create_annotated_heatmap(z, x=x, y=y,annotation_text=z_text, colorscale=colorscale, hoverinfo='none')
# Altering x axis
fig['layout']['xaxis']['tickfont']['family'] = 'Gill Sans MT'
fig['layout']['xaxis']['tickfont']['size'] = 12
fig['layout']['xaxis']['tickfont']['color'] = "black"
fig['layout']['xaxis']['tickangle'] = 0
# Altering x axis
fig['layout']['yaxis']['tickfont']['family'] = "Gill Sans MT"
fig['layout']['yaxis']['tickfont']['size'] = 12
fig['layout']['yaxis']['tickfont']['color'] = "black"
fig['layout']['yaxis']['tickangle'] = 25
# Altering main font
fig['layout']['font'] ["family"] = "Gill Sans MT"
fig['layout']['font']['size'] = 9
plotly.offline.iplot(fig,config={"displayModeBar": False},show_link=False,filename='pandas-heatmap')
正如你所看到的,今年8月到3月没有任何数据,因此显示为0.我不能删除这个,否则热图不起作用...所以我想我会将任何0的字体改为白色隐藏它们。但是我不知道该怎么做。
我发现这段代码改变了注释的字体大小,但是如果值== 0(因为'i'不是值),我不知道如何改变它来改变颜色
for i in range(len(fig.layout.annotations)):
fig.layout.annotations[i].font.size = 9