|
39 | 39 | from matplotlib._animation_data import (
|
40 | 40 | DISPLAY_TEMPLATE, INCLUDED_FRAMES, JS_INCLUDE, STYLE_INCLUDE)
|
41 | 41 | from matplotlib import _api, cbook
|
42 |
| - |
| 42 | +import matplotlib.colors as mcolors |
43 | 43 |
|
44 | 44 | _log = logging.getLogger(__name__)
|
45 | 45 |
|
@@ -1003,6 +1003,9 @@ def func(current_frame: int, total_frames: int) -> Any
|
1003 | 1003 |
|
1004 | 1004 | if savefig_kwargs is None:
|
1005 | 1005 | savefig_kwargs = {}
|
| 1006 | + else: |
| 1007 | + # we are going to mutate this below |
| 1008 | + savefig_kwargs = dict(savefig_kwargs) |
1006 | 1009 |
|
1007 | 1010 | if fps is None and hasattr(self, '_interval'):
|
1008 | 1011 | # Convert interval in ms to frames per second
|
@@ -1057,6 +1060,18 @@ def func(current_frame: int, total_frames: int) -> Any
|
1057 | 1060 | _log.info("Disabling savefig.bbox = 'tight', as it may cause "
|
1058 | 1061 | "frame size to vary, which is inappropriate for "
|
1059 | 1062 | "animation.")
|
| 1063 | + |
| 1064 | + facecolor = savefig_kwargs.get('facecolor', |
| 1065 | + mpl.rcParams['savefig.facecolor']) |
| 1066 | + if facecolor == 'auto': |
| 1067 | + facecolor = self._fig.get_facecolor() |
| 1068 | + |
| 1069 | + def _pre_composite_to_white(color): |
| 1070 | + r, g, b, a = mcolors.to_rgba(color) |
| 1071 | + return a * np.array([r, g, b]) + 1 - a |
| 1072 | + |
| 1073 | + savefig_kwargs['facecolor'] = _pre_composite_to_white(facecolor) |
| 1074 | + savefig_kwargs['transparent'] = False # just to be safe! |
1060 | 1075 | # canvas._is_saving = True makes the draw_event animation-starting
|
1061 | 1076 | # callback a no-op; canvas.manager = None prevents resizing the GUI
|
1062 | 1077 | # widget (both are likewise done in savefig()).
|
|
0 commit comments