簡體   English   中英

如何修復 Plotly Heatmap 塊大小?

[英]How to fix Plotly Heatmap block size?

這是我的熱圖繪圖功能:

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對象中。

結果是這樣的:(我不想看到情節上的灰色部分,我該怎么做

在此處輸入圖片說明

我認為這里發生的事情是出於某種原因將您的years輸入為數字,您可以通過添加來明確地分類這個變量

fig['layout']['xaxis']['type'] = 'category'

我在設置固定縱橫比時遇到了同樣的問題。

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

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

做這個 :

fig.update_xaxes(tickson='boundaries')
fig.update_yaxes(tickson='boundaries')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM