Stop the auto stretching of the subplots for images

Hello everyone ^^
As you can see in the image below, all the subplots of the images have been stretched how can I change it to keep the size of the images?

Screenshot from 2024-09-18 15-31-01

Thank you

Hi @User5
can you please share your code with us?

These are the functions I used to get to plot them.

def fig_mip(mip_X, mip_Y, mip_Z, title):
    fig = make_subplots(
        rows=2,
        cols=2,
        specs=[
            [{"type": "heatmap"}, {"type": "heatmap"}],
            [{"type": "heatmap"}, {"type": "heatmap"}],
        ],
        subplot_titles=("MIP X axis", "MIP Y axis", "MIP Z axis"),
    )
    fig = fig.add_trace(mip_X.data[0], row=1, col=1)
    fig = fig.add_trace(mip_Y.data[0], row=1, col=2)
    fig = fig.add_trace(mip_Z.data[0], row=2, col=1)
    fig = fig.update_layout(
        title_text=title, coloraxis=dict(colorscale="hot"), autosize=False
    )
    return fig


def mip_graphs(
    x0: int, xf: int, y0: int, yf: int, z: int, stack: Union[np.array, list]
):
    image_bead = stack[:, y0:yf, x0:xf]
    z_ima = stack[z, y0:yf, x0:xf]
    image_x = np.max(image_bead, axis=2)
    image_y = np.max(image_bead, axis=1)
    image_x = image_x / image_x.max()
    image_y = image_y / image_y.max()
    image_z = z_ima / z_ima.max()
    mip_x = px.imshow(
        image_x,
        zmin=image_x.min(),
        zmax=image_x.max(),
        color_continuous_scale="hot",
    )
    mip_y = px.imshow(
        image_y,
        zmin=image_y.min(),
        zmax=image_y.max(),
        color_continuous_scale="hot",
    )
    mip_z = px.imshow(
        image_z,
        zmin=image_z.min(),
        zmax=image_z.max(),
        color_continuous_scale="hot",
    )
    return mip_x, mip_y, mip_z

1 Like

@User5 would this work? "yaxis": { "scaleanchor": "x", ... }

1 Like

if I add that to the figure, it will be applied only on the first subplot and I can see that the range of the axis has changed as well.

Screenshot from 2024-09-19 09-47-28

def fig_mip(mip_x, mip_y, mip_z, title):
    fig = make_subplots(
        rows=2,
        cols=2,
        specs=[[{}, {}], [{"colspan": 2}, None]],
        subplot_titles=("MIP X axis", "MIP Y axis", "MIP Z axis"),
    )
    fig = fig.add_trace(mip_x.data[0], row=1, col=1)
    fig = fig.add_trace(mip_y.data[0], row=1, col=2)
    fig = fig.add_trace(mip_z.data[0], row=2, col=1)
    fig = fig.update_layout(
        title_text=title,
        coloraxis=dict(colorscale="hot"),
        autosize=False,
    )
    fig.update_layout({"yaxis": {"scaleanchor": "x"}})

    return fig

Hi @User5 !
When creating subplots, each subplot will have its own axes.
Here you should have x/y, x2/y2 and x3/y3

The parameters of those axes can be set in the layout like:

fig.update_layout(
    xaxis={...}, yaxis={...},
    xaxis2={...}, yaxis2={...},
    xaxis3={...}, yaxis3={...},
)

Then the parameters to use depends on what you want…

That’s why in your example, it applies only on the first plot.

2 Likes

@adamschroeder @Skiks Thank you for your replies. I actually tried it and it fixed the issue but I see some margins, the axis are not starting from 0. How can I fix this ?

Screenshot from 2024-09-19 13-39-49

@User5 try to use the parameter xaxis={'rangemode': "nonnegative"} for each xaxis