我正在使用 make_axes_locatable 来创建此布局的图:
如您所见,轴标签未对齐。我的代码如下所示:
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
fig, ax = plt.subplots()
plt.tight_layout()
ax.set_aspect("equal")
divider = make_axes_locatable(ax)
ax_histx = divider.append_axes("top", size="25%", pad="0.75%", sharex=ax)
ax_histy = divider.append_axes("right", size="25%", pad="0.75%", sharey=ax)
cax = divider.append_axes("right", size="4%", pad="0.75%")
hcax = divider.append_axes("top", size="4%", pad="0.75%")
ax.set_xlim(0,10000)
ax.set_ylim(0,10000)
ax.tick_params(axis='x', rotation=90)
ax.set_xlabel("xlabel")
ax_histy.set_xlabel("xlabel")
ax.set_ylabel("ylabel")
ax_histx.set_ylabel("ylabel")
fig.align_labels()
plt.show()
我添加了fig.align_labels()
代码,但没用。仅 x 或 y 轴的版本也不起作用。我使用的是 matplotlib 3.6.0