0

I struggle to save plot in fullsize screen. Consider the following code:

from qutip import *
import numpy as np
from numpy import *
from matplotlib.pyplot import *
import matplotlib.pyplot as plt
from mpmath import *
import mpmath as mpmath
import pylab
import numpy
import time
import numpy, scipy.io
from random import *
from scipy.integrate import quad

#matplotlib.pyplot.xticks(fontsize=40)
#matplotlib.pyplot.yticks(fontsize=40)
plt.rcParams['lines.linewidth'] = 3
plt.rcParams.update({'font.size': 35})
#%%
tot_power=valid_solutions[0][3]
TQ=80
TCl=100
k=2
R=2000
gamma=1000

names0 = [r'$T_{Cl}$', r'$T_{Q}$']
values0 = [TCl, TQ]

names1 = [r'$Q_{L}$', r'$Q_{P}$']
values1 = [0, 0]

names2 = [r'$W_{Lab \rightarrow Cl}$', r'$W_{Cl \rightarrow Q}$']
values2 = [0,  0]


plt.figure(figsize=(9, 3))
plt.subplot(131)
plt.bar(names0, values0)
plt.title('As')
plt.subplot(132)
plt.bar(names1, values1, log=True)
plt.title('B ($k=$' + str(k) + ')')
plt.subplot(133)
plt.bar(names2, values2, log=True)
plt.title('C')
plt.suptitle('$R=10^{' + str(np.log10(R)) + '}, T_1=$' + "{:.2e}".format(1/gamma) + "s")
#fig = plt.gcf()
#h, w = fig.get_size_inches()
#fig.set_size_inches(h*2, w*2)
manager = plt.get_current_fig_manager()
manager.window.showMaximized()
plt.savefig('foo.png', bbox_inches='tight')
plt.show()

If I open the picture, it is totally unreadable as you can see. enter image description here However it is indeed displayed (and readable) in fullscreen in python. I emphasize the fact I read many topic about this subject but no one solved my issue. Topics such as: How to make pylab.savefig() save image for 'maximized' window instead of default size or Saving Matplotlib graphs to image as full screen (I added some of those in my code as you can see, but it doesn't work).

The histogram are 0 just for the minimal working example, of course in practice they would have values.

I don't want to specify manually some inches for my windows, I want everything to be automatically saved as a fullscreen image.

Last info: matplotlib.get_backend() returns me 'Qt5Agg' (I have seen it can be usefull for some fixes)

StarBucK
  • 209
  • 4
  • 18
  • "automatically fullscreen" is not well defined. I might be coding on a small 11" laptop, or might be using a giant 4k display. What size should you define for? Do you want to use say font size 11 for both cases? Do you want your graph to remain the same size relative to text? The only solution I see is to define a figure size. – VBB May 28 '20 at 11:29
  • @VBB i want the image to have the same shape as when it is shown in the window figure in python. Because of the options put in python figure window it is directly shown in fullscreen. – StarBucK May 28 '20 at 11:32
  • You could use savefig from the interface for the first time, then take those as the figsize? – VBB May 28 '20 at 11:48

0 Answers0