Skip to content

Bug Report: saved Figure ignores figure.facecolor #17467

Closed

Description

@DanielGoldfarb

Bug report

When saving a figure, either via plt.savefig() or by clicking the disk icon on the figure display UI, the saved figure has no facecolor.

Code for reproduction

dino@DINO:~/code/mplfinance$ ipython
Python 3.7.4 (default, Aug 13 2019, 20:35:49)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import matplotlib as mpl

In [2]: mpl.__version__
Out[2]: '3.1.3'

In [3]: import matplotlib.pyplot as plt

In [4]: y = [2,4,3,7,1]
In [5]: x = [0,1,2,3,4]

In [6]: plt.rcParams['figure.facecolor'] = 'c'

In [7]: plt.plot(x,y)
Out[7]: [<matplotlib.lines.Line2D at 0x7ff9eeb49090>]

In [8]: plt.show()

In [9]: plt.rcParams['figure.facecolor'] = 'c'
In [10]: plt.plot(x,y)
Out[10]: [<matplotlib.lines.Line2D at 0x7ff9d7890d10>]

In [11]: plt.savefig('testsave.png')

Here is what the plot looks like upon plt.show()

matplotlib_fig1


Here is what the plot looks like when I click the disk icon on the above UI to save the plot:

matplotlib_fig1saved


Here is what the plot looks like when I call plt.savefig('testsave.png')

matplotlib_testsave

Activity

  1. anntzer commented on May 20, 2020

    @anntzer
    Contributor

    Almost certainly fixed by #15111 in the next release of matplotlib?

  2. tacaswell commented on May 20, 2020

    @tacaswell
    Member

    We have both rcParams['savefig.facecolor'] and rcParams['figure.facecolor']. The first get used when saving, the second get used when shown interactively. This is a hold over from what the default background color in the GUI was a light gray but you wanted to save it with a white background.

    This is partially fixed by #15111 (which at at least makes it possible mostly ignore setting the 'savefig.facecolor', however for supporting released versions you will need to set both.

  3. QuLogic commented on May 20, 2020

    @QuLogic
    Member

    Going to close this then, since it'll be fixed soon.

  4. added this to the v3.3.0 milestone on May 20, 2020
  5. DanielGoldfarb commented on May 20, 2020

    @DanielGoldfarb
    Author

    Thanks all!
    Will use rcParams['savefig.facecolor'] as a workaround in the meantime.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions