How to set Matplotlib *Border* `top` in Python without manually specifying it in *Configure subplots*?
Sep 29, 11:48pm

The GUI's "Configure subplots" / "Border" sliders just write the same subplot parameters you can set from code — so you can reproduce the top slider with subplots_adjust:

python
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([1, 2, 3])

# top is the position of the top edge of the subplots,
# as a fraction of the figure height (e.g. 0.9)
plt.subplots_adjust(top=0.9)      # pyplot style
# or equivalently:
fig.subplots_adjust(top=0.9)      # object-oriented style

plt.show()

Other ways to control it without touching the GUI:

python
# 1. As a global default for all figures (before creating them)
plt.rcParams['figure.subplot.top'] = 0.9

# 2. Let matplotlib compute margins automatically
plt.tight_layout()                       # one-shot adjustment
fig.set_tight_layout(True)              # re-apply on every draw
fig, ax = plt.subplots(layout='constrained')  # constrained layout, generally preferred

# 3. Open the same tool programmatically (GUI equivalent)
plt.subplot_tool()

Notes:

  • top is a fraction of figure height, so top=1.0 puts the subplot flush against the figure top edge (this is what plt.subplots_adjust(left=0, right=1, top=1, bottom=0) does for full-bleed plots) (Stack Overflow).
  • For automatic label-fitting, tight_layout or constrained layout is simpler than hand-tuning top (Matplotlib docs, Matplotlib docs).
Sep 29, 11:48pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more