Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add scrollbars when needed to preserve specified figure size #7338

Description

@Khris777

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesNew featurekeepItems to be ignored by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions