Saving Matplotlib graphs to image as full screen
As one more option, I think it is also worth looking into
plt.savefig('filename.png', bbox_inches='tight')
This is especially useful if you're doing subplots
that has axis labels which look cluttered.
The method you use to maximise the window size depends on which matplotlib backend you are using. Please see the following example for the 3 most common backends:
import matplotlib.pyplot as plt
plt.figure()
plt.plot([1,2], [1,2])
# Option 1
# QT backend
manager = plt.get_current_fig_manager()
manager.window.showMaximized()
# Option 2
# TkAgg backend
manager = plt.get_current_fig_manager()
manager.resize(*manager.window.maxsize())
# Option 3
# WX backend
manager = plt.get_current_fig_manager()
manager.frame.Maximize(True)
plt.show()
plt.savefig('sampleFileName.png')
You can determine which backend you are using with the command matplotlib.get_backend()
. When you save the maximized version of the figure it will save a larger image as desired.
For everyone, who failed to save the plot in fullscreen using the above solutions, here is what really worked for me:
figure = plt.gcf() # get current figure
figure.set_size_inches(32, 18) # set figure's size manually to your full screen (32x18)
plt.savefig('filename.png', bbox_inches='tight') # bbox_inches removes extra white spaces
You may also want to play with the dpi (The resolution in dots per inch)
plt.savefig('filename.png', bbox_inches='tight', dpi=100)