日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Python?matplotlib繪圖時指定圖像大小及放大圖像詳解_python

作者:淡竹云開 ? 更新時間: 2022-07-02 編程語言

matplotlib繪圖時是默認的大小,有時候默認的大小會感覺圖片里的內容都被壓縮了,解決方法如下。

先是原始代碼:

from matplotlib import pyplot as plt

plt.figure(figsize=(1,1))

x = [1,2,3]
plt.plot(x, x)
plt.show()

關鍵的代碼是plt.figure(figsize=(1,1)),生成的圖片如下

修改代碼,放大圖片:

from matplotlib import pyplot as plt

plt.figure(figsize=(10,10))

x = [1,2,3]
plt.plot(x, x)
plt.show()

這時候橫坐標和縱坐標都放大了10倍:

如果想要指定像素,可以這么做:

from matplotlib import pyplot as plt

plt.figure(dpi=80)

x = [1,2,3]
plt.plot(x, x)
plt.show()

更多參考資料:python - How do you change the size of figures drawn with matplotlib? - Stack Overflow

附:matplotlib繪圖時橫縱坐標和圖例的字體大小如何設置

橫縱坐標字體大小調節:

通過fontsize可以進行調節

ax1.set_ylabel("AUC",fontsize=20)
ax2.set_ylabel("Logloss",fontsize=20)

圖例字體大小調節:

在plt.legend中加一個

prop={"size":18,"weight":"black"}

即可

總結

原文鏈接:https://zhang0peter.blog.csdn.net/article/details/90734660

欄目分類
最近更新