如何修复 Plotly 热图块大小?

问题描述 投票:0回答:3

这是我的热图绘图函数:

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

结果是这样的:(我不想看到图上的灰色部分,我该怎么做)

Enter image description here

python plotly heatmap
3个回答
3
投票

我在将固定纵横比设置为图形时遇到了同样的问题。

在这里找到答案 https://plotly.com/python/axes/#fixed-ratio-axes-with-compressed-domain

fig['layout']['xaxis']['constrain'] = 'domain'

2
投票

我认为这里发生的事情是,由于某种原因,你的

years
输入会变成数字,你可以通过添加

使这个变量明确分类
fig['layout']['xaxis']['type'] = 'category'

1
投票

这样做:

fig.update_xaxes(tickson='boundaries')
fig.update_yaxes(tickson='boundaries')
© www.soinside.com 2019 - 2024. All rights reserved.