一般問題:我的可視化在邊緣被切割,我找到了一種手動更正它的方法。但是有沒有可以自己完成的命令?
我正在使用 PyzoPython 3.9.5用Matplotlib.pyplot(版本 3.4.2)撰寫 Python ( )
當我想查看我繪制的(使用
plot.show())命令繪制的圖形時,我在單獨的視窗中獲得了該圖形,但它似乎被剪切了(尤其是邊緣:標題),如下圖所示:
然后,我試著把它放在全視窗中。它稍微好一點,但仍然被切割(尤其是頂部):

所以我開始研究在 中可以訪問的引數Subplot Configuration Tool,并通過更改top值,我能夠使我的情節完全可見:
Subplot Configuration Tool:
- 將
top值修改為 后0.95:
Thus, I was wondering if there was a way to change the value directly in the code instead of having to deal with it manually each time.
Note : In the past, I had to use figsize=(x_width,y_width) as a parameter in plt.subplots() but it doesn't change anything here (at most, I can have the first picture above)
Recap :
- Is there a way to make sure, nothing will be cut in the visualisation of the plot (Title of the plot Titles of the axis) with a command ?
uj5u.com熱心網友回復:
- 您可以使用
plt.subplots_adjust()(https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots_adjust.html)手動執行此操作 - 您可以使用
plt.figure(constrained_layout=True)(https://matplotlib.org/stable/tutorials/intermediate/constrainedlayout_guide.html)自動執行此操作 - 您可以使用
plt.tight_layout()而不是使用 constrained_layout 來自動執行此操作。但是,一般情況下,受約束的布局更靈活。 https://matplotlib.org/stable/tutorials/intermediate/tight_layout_guide.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/357833.html
標籤:python matplotlib
