How to fix Plotly Heatmap block size?

Viewed 3078

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.

Result is like this : (I don't want to see the grey parts on the plot, how can I do that)

enter image description here

3 Answers

I think what's happening here is that for some reason plotly takes your years input to be numerical, you can make this variable explicitly categorical by adding

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

do this :

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

Related