Skip to content

Commit 3c83237

Browse files
committed
Set the GTK background color to white.
This is consistent with the other backends (although this seems to be broken on wx too), which allows semi-transparent figures to be rendered against a consistent background (this can be checked e.g. with `figure(facecolor=(0, 0, 0, 0))` or `figure(facecolor=(1, 1, 1, .5))`), which would previously be rendered differently on gtk3 when using a dark theme.
1 parent e24244c commit 3c83237

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/matplotlib/backends/backend_gtk3.py

+6
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ def __init__(self, figure=None):
127127

128128
self.set_can_focus(True)
129129

130+
css = Gtk.CssProvider()
131+
css.load_from_data(b".matplotlib-canvas { background-color: white; }")
132+
style_ctx = self.get_style_context()
133+
style_ctx.add_provider(css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
134+
style_ctx.add_class("matplotlib-canvas")
135+
130136
renderer_init = _api.deprecate_method_override(
131137
__class__._renderer_init, self, allow_empty=True, since="3.3",
132138
addendum="Please initialize the renderer, if needed, in the "

0 commit comments

Comments
 (0)