如何將 Matplotlib/Pylab 圖表中的 Y 軸標籤水平列印?
只需使用 plt.ylabel(rotation='horizontal'),我們就可以根據我們的需求對齊標籤。
步驟
使用 [0, 5] 和 [0, 5] 列表繪製直線。
透過傳遞 rotation='horizontal' 使用 ylabel 方法為 Y 軸設定 y 標籤。
使用 xlabel 方法為 X 軸設定 x 標籤。
使用 plt.show() 方法顯示圖形。
示例
from matplotlib import pyplot as plt plt.plot([0, 5], [0, 5]) plt.ylabel("Y-axis ", rotation='horizontal') plt.xlabel("X-axis ") plt.show()
輸出
廣告