我試圖在matplotlib. 因為我不需要任何子圖,所以我沒有使用 figure.add_subplot() 方法。
fig = plt.figure()
plt.plot(series1)
plt.plot(series2)
plt.xlabel('Date')
plt.ylabel("Values")
plt.legend(loc='best')
plt.title(Plot title)
fig.autofmt_xdate()
plt.savefig("fig.png", format="png")
但是,上述格式適用于一些短系列,而對于長系列,即使它們隨autofmt_xdate()命令旋轉,x-ticks 也有相當多的重疊。我知道ax.set_major_locator()使用子圖時的 解決方案,但在使用plt.figure().
uj5u.com熱心網友回復:
您可以使用以下方法獲取軸的實體:
ax = plt.gca()
然后,您可以使用您通常在軸上使用的方法:
ax.xaxis.set_major_locator(....)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/335138.html
標籤:Python matplotlib 阴谋 xticks
上一篇:Matplotlib渲染正確
