简体   繁体   English

如何修复 Plotly Heatmap 块大小?

[英]How to fix Plotly Heatmap block size?

Here is my HeatMap plot function :这是我的热图绘图功能:

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)

Right now my work around is height = round(60 * len(k_list)) if round(60 * len(k_list)) > 640 else 640, in the *Layout object.现在我的工作是height = round(60 * len(k_list)) if round(60 * len(k_list)) > 640 else 640,*Layout对象中。

Result is like this : ( I don't want to see the grey parts on the plot, how can I do that )结果是这样的:(我不想看到情节上的灰色部分,我该怎么做

在此处输入图片说明

我认为这里发生的事情是出于某种原因将您的years输入为数字,您可以通过添加来明确地分类这个变量

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

I meet the same problem while setting fixed aspect ratio to figure.我在设置固定纵横比时遇到了同样的问题。

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

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

do this :做这个 :

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM