多图中的刻度线长度相同

Same length of ticks in multiplot

如何设置所有子图中的刻度数相同scale/length?我想根据第四个子图设置所有 xticks 的长度。我的意思是所有名为 y 的轴在刻度 0 和 2 之间将具有相同的 space,所有名为 x 的轴将在 -1 和 0 之间具有相同的 space。也许将 plot 设置为广场。请问如何?

import numpy as np
import matplotlib.pyplot as plt
from numpy import array
import matplotlib as mpl

x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)

# Plot figure with size
fig, ax = plt.subplots(sharex=True)
plt.figure(figsize=(12, 9))

# Subplots
fig1 = plt.subplot(231)
plt.plot(x, y**2)
fig1.set_xlim(0e-13,2e-13)
fig1.set_ylim(-1.15e-14,0.01e-14)

fig2=plt.subplot(232)
plt.plot(x, y**2)
fig2.set_xlim(0e-13,2e-13)
fig2.set_ylim(-7.3e-15,7.3e-15)

fig3=plt.subplot(233)
plt.plot(x, y**2)
fig3.set_ylim(0e-13,1.2e-13)
fig3.set_xlim(0e-13,2e-13)

# Subplots with arrows
fig4=plt.subplot(234)
plt.plot(x, y**2)
fig4.set_xlim(-1.15e-14,0.01e-14)
fig4.set_ylim(-7.3e-15,7.3e-15)

fig5=plt.subplot(235)
plt.plot(x, y**2)
fig5.set_xlim(-7.3e-15,7.3e-15)
fig5.set_ylim(0e-13,1.2e-13)
plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=1.0)

fig6=plt.subplot(236)
plt.plot(x, y**2)
fig6.set_xlim(-1.5e-14,0e-14)
fig6.set_ylim(0e-13,1.2e-13)

plt.show()

by @ImportanceOfBeingErnest 概述了实现此目标的最佳方法。基本上,您手动计算缩放以遵守每个现有轴的 yx 限制之间的比率,例如

fig1.set_aspect(np.diff(fig1.get_xlim())/np.diff(fig1.get_ylim()))

但请注意,这必须在调用 set_ylim()set_xlim() 之后完成,因为它必须使用 final 限制才能正确计算必要的比例。 set_xticks()set_yticks() 可以在之前或之后安全地调用,效果相同。

将此应用于六个 axes 中的每一个将产生