y 在 ipython 中的 matplotlib 中被切断

y ticks cutting off in matplotlib in ipython

我正在 ipython 中绘制 matplotlib 图表,但我的 y-ticks 被截断了。

我厌倦了使用 plt.tight_layout()plt.autoscale(),但两者似乎都不起作用。如何让刻度线完全显示?

我的代码是:set1set2 是相同大小的列表

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import mpld3

fig, ax = plt.subplots()
fig.canvas.draw()
x = np.arange(1,len(set1)+1,1)

ax.scatter(x, set1, c='blue', s=200, alpha=0.5)
ax.scatter(x, set2, c='red', s=200, alpha=0.5)
ax.grid(color='lightgray', alpha=0.7)
plt.xlim(0,500)
plt.tight_layout()
#plt.autoscale()
mpld3.display(fig)

您可以使用 subplots_adjust

调整轴对象的边缘位置

例如

fig, ax = plt.subplots()
fig.subplots_adjust(left=0.2)  #Adjust 0.2 to find the right margin for your plot

我认为 tight_layout 会覆盖此设置,因此您可能需要将其关闭。