Home > Back-end >  Matplotlib axis break with different size subplots
Matplotlib axis break with different size subplots

Time:09-03

I'm making a plot with an x-axis break // using different size subplots as described in enter image description here

CodePudding user response:

You need to introduce a factor f taking into account the different axis scales:

d = .015 # how big to make the diagonal lines in axes coordinates
f = (np.diff(ax1.get_xlim()) / np.diff(ax2.get_xlim())).item()
# arguments to pass plot, just so we don't keep repeating them
kwargs = dict(transform=ax1.transAxes, color='k', clip_on=False)
ax1.plot((1-d*f,1 d*f), (-d, d), **kwargs)
ax1.plot((1-d*f,1 d*f),(1-d,1 d), **kwargs)

kwargs.update(transform=ax2.transAxes)  # switch to the bottom axes
ax2.plot((-d, d), (1-d,1 d), **kwargs)
ax2.plot((-d, d), (-d, d), **kwargs)

enter image description here


Update:
An easier way is to use the approach shown in the official enter image description here

  • Related