Skip to content

tight_layout + lots of subplots + long ylabels inverts yaxis #8062

@NelleV

Description

@NelleV

When plotting a lot of subplots (here 6), with long y-labels and tight_layout, the y-axis is reverted.
In this example, it is particularly striking as I am plotting histograms.

import matplotlib.pyplot as plt
import numpy as np

alphas = [0.001, 0.1, 1, 10, 1000, 10000]
X = np.random.randn(len(alphas), 1000)

fig, axes = plt.subplots(nrows=len(alphas),  ncols=2)
fig.set_tight_layout(True)
for i, alpha in enumerate(alphas):
    ax = axes[i, 0]
    ax.hist(X[i])
    ax.set_xlabel("Number of features", fontweight="bold")
    ax.set_ylabel("Number of genes", fontweight="bold")

    ax = axes[i, 1]
    ax.plot(sorted(X[i]))
    ax.set_ylabel("Number of genes", fontweight="bold")

mpl_bug

Expected outcome

Removing the tight layout, the labels collapse, but at least the plots are oriented the correct way.

mpl_bug_wo_tight_layout

Matplotlib should either raise a proper error raise a proper warning, or plot the histograms in the proper order.

Matplotlib version

Matplotlib 2.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions