I’m trying to automate the process of removing all space between subplots that share axes, and I’m struggling to achieve more fine-grained control over the constrained layout calculation. Would appreciate feedback if I’m missing something or confirmation that my observations are bugs or reasonable feature requests.
I can’t seem to, e.g., exclude tick labels or axes titles via set_in_layout, e.g., with
%matplotlib inline
import matplotlib.pyplot as plt
rc = {
"xtick.direction": "in",
"ytick.direction": "in",
"figure.constrained_layout.use": True,
"figure.constrained_layout.h_pad": 0,
"figure.constrained_layout.w_pad": 0,
"figure.constrained_layout.wspace": 0,
"figure.constrained_layout.hspace": 0,
"axes.labelpad": 0,
}
with plt.style.context(rc):
fig, axes = plt.subplots(2, 2, figsize=(6, 4), sharey=True, sharex=True)
axes[0, 0].axis("off")
axes[0, 0].set_in_layout(False)
for artist in axes[0, 0].get_children():
artist.set_in_layout(False)
title = axes[1, 0].set_title("title")
title.set_in_layout(False)
for ax in axes.flat[1:]:
ax.set_ylim(-0.1, 1.1)
ax.set_xlim(-0.1, 1.1)
fig.canvas.draw()
(See this issue for the reason for the
fig.canvas.draw call.)
Maybe I don’t understand what to expect of set_in_layout, because my attempt above to remove all elements in the upper-left panel from the layout has no effect. (Perhaps axes that are turned off should automatically be excluded from the layout calculation - that’s what I would expect, at least.)
I’d also love an automated way to prune ticks whose labels extend beyond the axes limits - is there one, or might this be a good feature proposal?
