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:

import numpy as np
import proplot as plot

# simple function to extract axis widths
def get_widths(axs):
    return np.array([ax.get_position().bounds[2] for ax in axs])

# plot geometry
array = [[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 reference
fig, axs = plot.subplots(array, hratios=(2, 2, 2.5), ref=5)

# check the widths
widths = 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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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