In the discussion of this post: #3139 I found the following quote by @efiring :
When the figure is rendered on the screen, the geometry does change the output of fig.get_size_inches(), and savefig uses the modified dimensions. It's not clear that there is anything we should change here.
So here's an example where I explicitely set a certain figure size using rcParams:
import pandas as pd
import matplotlib as mp
import matplotlib.pyplot as mpp
import numpy as np
dpi = 200
mp.rcParams[u'figure.dpi'] = dpi
mp.rcParams[u'figure.figsize'] = (8.,12.)
mp.rcParams[u'savefig.dpi'] = dpi
df = pd.DataFrame({'A':np.random.rand(20),'B':np.random.rand(20)})
fig, axes = mpp.subplots(1,1)
axes.scatter(y=df.A, x=df.B)
print fig.get_size_inches()
fig.savefig("C:\\DataDir\\Output\\Test1.png")
print fig.get_size_inches()
fig.show()
print fig.get_size_inches()
fig.savefig("C:\\DataDir\\Output\\Test2.png")
print fig.get_size_inches()
mp.rcdefaults()
print statements output:
[ 8. 12.]
[ 8. 12.]
[ 8. 4.77]
[ 8. 4.77]
For my use-case having show() silently alter the figure size is unwanted behaviour, I'm expecting the figure size to only change when I'm explicitely changing it myself.
I can see how there are use-cases where this behaviour is expected, so I'm not saying to get rid of it, rather give the user a choice in some way, either by setting a global parameter, by telling savefig() to use rcParams[u'figure.figsize'] instead of fig.get_size_inches() when saving the figure, or however else this could be implemented nicely.
Invoking
fig.set_figwidth(mp.rcParams[u'figure.figsize'][0])
fig.set_figheight(mp.rcParams[u'figure.figsize'][1])
everytime after doing show() isn't a handy solution in any way.
In the discussion of this post: #3139 I found the following quote by @efiring :
So here's an example where I explicitely set a certain figure size using
rcParams:printstatements output:For my use-case having
show()silently alter the figure size is unwanted behaviour, I'm expecting the figure size to only change when I'm explicitely changing it myself.I can see how there are use-cases where this behaviour is expected, so I'm not saying to get rid of it, rather give the user a choice in some way, either by setting a global parameter, by telling
savefig()to usercParams[u'figure.figsize']instead offig.get_size_inches()when saving the figure, or however else this could be implemented nicely.Invoking
everytime after doing
show()isn't a handy solution in any way.