|
38 | 38 | from matplotlib._animation_data import (
|
39 | 39 | DISPLAY_TEMPLATE, INCLUDED_FRAMES, JS_INCLUDE, STYLE_INCLUDE)
|
40 | 40 | from matplotlib import _api, cbook
|
41 |
| - |
| 41 | +import matplotlib.colors as mcolors |
42 | 42 |
|
43 | 43 | _log = logging.getLogger(__name__)
|
44 | 44 |
|
@@ -1012,6 +1012,9 @@ def func(current_frame: int, total_frames: int) -> Any
|
1012 | 1012 |
|
1013 | 1013 | if savefig_kwargs is None:
|
1014 | 1014 | savefig_kwargs = {}
|
| 1015 | + else: |
| 1016 | + # we are going to mutate this below |
| 1017 | + savefig_kwargs = dict(savefig_kwargs) |
1015 | 1018 |
|
1016 | 1019 | if fps is None and hasattr(self, '_interval'):
|
1017 | 1020 | # Convert interval in ms to frames per second
|
@@ -1067,6 +1070,18 @@ def func(current_frame: int, total_frames: int) -> Any
|
1067 | 1070 | _log.info("Disabling savefig.bbox = 'tight', as it may cause "
|
1068 | 1071 | "frame size to vary, which is inappropriate for "
|
1069 | 1072 | "animation.")
|
| 1073 | + |
| 1074 | + facecolor = savefig_kwargs.get('facecolor', |
| 1075 | + mpl.rcParams['savefig.facecolor']) |
| 1076 | + if facecolor == 'auto': |
| 1077 | + facecolor = self._fig.get_facecolor() |
| 1078 | + |
| 1079 | + def _pre_composite_to_white(color): |
| 1080 | + r, g, b, a = mcolors.to_rgba(color) |
| 1081 | + return a * np.array([r, g, b]) + 1 - a |
| 1082 | + |
| 1083 | + savefig_kwargs['facecolor'] = _pre_composite_to_white(facecolor) |
| 1084 | + savefig_kwargs['transparent'] = False # just to be safe! |
1070 | 1085 | # canvas._is_saving = True makes the draw_event animation-starting
|
1071 | 1086 | # callback a no-op; canvas.manager = None prevents resizing the GUI
|
1072 | 1087 | # widget (both are likewise done in savefig()).
|
|
0 commit comments