X Tutup
Skip to content

Interactive save should respect 'savefig.facecolor' rcParam. #3437

@u55

Description

@u55

Hi matplotlib developers,

Currently, there is no way to set the figure facecolor when saving a figure interactively via the NavigationToolbar2 graphical save button. All interactive backends, that I have tested, default to a white facecolor while ignoring the 'savefig.facecolor' rcParam. I propose to change this behavior such that every backend will respect the 'savefig.facecolor' rcParam.

One possible option would be to edit the save_figure method of each backend-specific class which inherits from matplotlib.backend_bases.NavigationToolbar2 in every backend. This seems tedious.

Another option would be to edit the print_figure method in matplotlib.backend_bases.FigureCanvasBase, which every backend inherits from. This seems simpler.

For instance, adding the following indicated lines to matplotlib.backend_bases.FigureCanvasBase.print_figure works for me.

def print_figure(self, filename, dpi=None, facecolor=None, edgecolor='w', # <---- facecolor default changed to None
                     orientation='portrait', format=None, **kwargs):

    ...

    if dpi is None:
        dpi = rcParams['savefig.dpi']

    if facecolor is None:  #  <---- added
        facecolor = rcParams['savefig.facecolor']  # <---- added

    origDPI = self.figure.dpi
    origfacecolor = self.figure.get_facecolor()
    origedgecolor = self.figure.get_edgecolor()

    self.figure.dpi = dpi
    self.figure.set_facecolor(facecolor)
    self.figure.set_edgecolor(edgecolor)

    ...

I don't use a custom 'edgecolor' often, but the interactive figure saving functionality should also be changed to use the 'savefig.edgecolor' rcParam.

I would be happy to create a pull request if the developers agree that this change is a good idea.
Thank you.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    X Tutup