79111902

Date: 2024-10-21 22:24:20
Score: 1
Natty:
Report link

My answer illustrates a frequent motivation to move only the x-axis: stacked diagrams with different horizontal axes but hspace=0.

import numpy as np
from matplotlib.pyplot import subplots

t = np.linspace(0, 3*np.pi)
U = np.sin(t)
x = np.linspace(-4, 4)
y = 1/(1 + x**2)

fig, (ax1, ax2) = subplots(2, 1, figsize=(8, 5), gridspec_kw={'hspace': 0})
ax1.plot(t, U)
ax1.spines['bottom'].set_position(('data', 0)) #'zero')
ax2.plot(x, y)
ax2.set_ylim(0)
fig.tight_layout()
fig.show()

The result

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Rainald62