Skip to content

Width/height ratios not obeyed in complex plots with extra space #221

Description

@mmagnuski

Description

Setting share=0 in plot.subplots leads to (some) axes having non-equal width.

Steps to reproduce

Before using share=0 everything looks good, the axes in the middle row have the same width:

importnumpyasnpimportproplotasplot# simple function to extract axis widthsdefget_widths(axs):
returnnp.array([ax.get_position().bounds[2] foraxinaxs])
# plot geometryarray= [[1, 1, 1, 2, 2, 2],
[3, 3, 4, 4, 5, 5],
[6, 6, 7, 7, 8, 8]]
# axis in the second row is the referencefig, axs=plot.subplots(array, hratios=(2, 2, 2.5), ref=5)
# check the widthswidths=get_widths(axs[2:5])
print(widths)
print('all widths equal:', (widths==widths[0]).all())

This gives the following figure:

and prints:

[0.29239766 0.29239766 0.29239766]
all widths equal: True

However, when I add share=0 to the plot.subplots - the middle axis in the second row shrinks more than the outer axes:

fig, axs=plot.subplots(array, hratios=(2, 2, 2.5), ref=5, share=0)

checking the widths, I have to call fig.canvas.draw() to get the actual widths, because if the code below is run is the same code cell as the previous I first get widths that are not compatible width what I see in the figure:

widths=get_widths(axs[2:5])
print(widths)
print('all widths equal:', (widths==widths[0]).all())
fig.canvas.draw()
widths=get_widths(axs[2:5])
print(widths)
print('all widths equal:', (widths==widths[0]).all())

which prints:

[0.26041667 0.26041667 0.26041667]
all widths equal: False
[0.2920774 0.2616831 0.2920774]
all widths equal: False

only the widths captured after figure redraw align with what I see in the figure.
But that is not so surprising, the actual issue are the non-equal widths of the axes in the second and third row.

Proplot version

0.6.4

PS. Thanks for the great package, makes creating complex multi-panel figures much easier!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions