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

Skip to content

Initial plot window ignoring rcParams figure.figsize #10555

Closed
@oliversheridanmethven

Description

@oliversheridanmethven

Original plotting window does not initially respect rcParams value


Summary

I import matplotlib and then set the rcParams by mpl.rcParams.update( {'figure.figsize': (15, 9.3)}). When I attempt to plot the window, its size is plotted instead as [10.35, 9.3] and not what I originally specified. This has onlst started occuring since I upgraded to a larger monitor. It does not occur for all inputs, and the larger (32, 20) plots correctly the first time.


Details

I have previously used the following to ensure my figure-size in my plots is a consistent size:

import matplotlib as mpl
rc_fonts = {'figure.figsize': (15, 9.3)}
mpl.rcParams.update(rc_fonts)
import matplotlib.pylab as plt

However, I am now finding that for my usual default values (15, 9.3) this is being ignored. The following demonstrates this (This must be run in stages, see current output section):

import matplotlib as mpl
rc_fonts = {'figure.figsize': (15, 9.3)}
mpl.rcParams.update(rc_fonts)
import matplotlib.pylab as plt
# I draw some boring plot. 
plt.clf()
plt.plot(*[range(10)]*2)
print plt.gcf().get_size_inches()
print mpl.rcParams['figure.figsize']
plt.gcf().set_size_inches(15, 9.3, forward=True)
print plt.gcf().get_size_inches()

The initial plot size is [10.35, 9.3] and after it is [15, 9.3] as desired. If however I make the default very much large or smaller, e.g. (32, 19.3) then the figure window is correctly sized. I thought setting rcParams is the recommended route?

Details:

  • Python 2.7.12 (inside a virtual environment, a must).
  • Backend TkAgg (I want this kept as it is).
  • Matplotlib version 2.1.0. (This bug/feature persists in version 2.1.2 also).

I have tried this inside and outside a virtual environment, and also tried Matplotlib versions 2.2 with python 3.5, and still it persists, and with all the backends I can muster (including Qt5Agg).

Possible known issue:

I have found the following issue 2716 which I think could be related, but there don't appear any fixes suitable for the rcParam settings route.

Current output:

Following the comments below is some example output (done using Python 3 to allow me to install the latest version of matplotlib):

Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
>>> 
... import matplotlib as mpl
... print(mpl.__version__)
... rc_fonts = {'figure.figsize': (15, 9.3)}
... mpl.rcParams.update(rc_fonts)
... import matplotlib.pylab as plt
... plt.plot(*[range(10)]*2)
... 
Backend Qt4Agg is interactive backend. Turning interactive mode on.
2.2.0rc1+124.gf1f83f6
>>> 
... print(plt.gcf().get_size_inches())
... print(mpl.rcParams['figure.figsize'])
... plt.gcf().set_size_inches(15, 9.3, forward=True)
... print(plt.gcf().get_size_inches())
... 
[ 10.35   9.3 ]
[15.0, 9.3]
[ 15.    9.3]

DEMONSTRATION

enter image description here

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions