这是我的热图绘图函数:
def plot_heatmap(alphas, k_list, title_prefix="", years=["Y2013", "Y2014"]):
data = [
Heatmap(
name = "",
z = alphas,
x = years,
y = k_list,
hoverongaps = False,
zauto = False,
zmin = zmin,
zmax = zmax,
colorscale = color_custom,
colorbar = dict(
title = "Alpha Value",
thicknessmode = "pixels",
thickness = 50,
yanchor = "top",
y = 1,
len = 480,
lenmode = "pixels",
ticks = "outside",
dtick = zmax / 10
)
)
]
fig = Figure(
data = data,
layout = Layout(
width = 640,
height = round(60 * len(k_list)) if round(60 * len(k_list)) > 640 else 640,
# autosize = True,
title = title_prefix + " | HeatMap : alphas",
)
)
fig.data[0]['hoverinfo'] = 'all'
fig['layout']['yaxis']['scaleanchor'] = 'x'
iplot(fig)
现在我的解决办法是
height = round(60 * len(k_list)) if round(60 * len(k_list)) > 640 else 640,
对象中的 *Layout
。
结果是这样的:(我不想看到图上的灰色部分,我该怎么做)
我在将固定纵横比设置为图形时遇到了同样的问题。
在这里找到答案 https://plotly.com/python/axes/#fixed-ratio-axes-with-compressed-domain
fig['layout']['xaxis']['constrain'] = 'domain'
我认为这里发生的事情是,由于某种原因,你的
years
输入会变成数字,你可以通过添加 使这个变量明确分类
fig['layout']['xaxis']['type'] = 'category'
这样做:
fig.update_xaxes(tickson='boundaries')
fig.update_yaxes(tickson='boundaries')