Savefig Outputs Blank Image - Troubleshooting
When using Matplotlib to save plots, it can be encountered that the resulting images are blank. To resolve this issue, consider the following factors:
subplot() Positioning:
Verify the subplot() positions carefully, ensuring that the plots are placed correctly. Try adjusting the values passed to matplotlib as suggested in the answer, especially when using conditional statements.
Figure Handling:
By default, Matplotlib creates a new figure when plt.show() is called. To prevent this and save the desired figure, call plt.savefig() before calling plt.show(). Alternatively, create a Figure object using plt.gcf() and save the figure using its savefig() method at any time.
Here's an example with both methods:
Before plt.show()
plt.savefig('tessstttyyy.png', dpi=100) plt.show()
Using plt.gcf()
fig1 = plt.gcf() plt.show() plt.draw() fig1.savefig('tessstttyyy.png', dpi=100)
Additional Considerations:
以上是為什麼我的 Matplotlib Savefig 輸出空白影像?的詳細內容。更多資訊請關注PHP中文網其他相關文章!