这通常是由于坐标轴边框的一些样式设置引起的。您可以使用以下代码示例来设置正确的边界框:
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import Divider, Size
fig = plt.figure(figsize=(6, 6))
# set up the AxesDivider
divider = Divider(fig, (0.1, 0.1, 0.8, 0.8), [Size.Fixed(0.4), Size.Fixed(0.6)],
[Size.Fixed(0.4), Size.Fixed(0.6)])
# create the Axes using the divider
ax = divider.append_axes("bottom", size=1.6, pad=0.6)
# set the tick locations and labels
ax.set_yticks([0, 1, 2, 3])
ax.set_yticklabels(["A", "B", "C", "D"])
# set the border style
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_linewidth(1.5)
ax.spines['bottom'].set_color('gray')
ax.spines['left'].set_linewidth(1.5)
ax.spines['left'].set_color('gray')
plt.show()
请注意,在上述示例中,我们对底部和左侧边框使用了相同的线宽和颜色,以获得一致的外观。您可以根据需要调整这些设置。