Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can set it by, for example <a href="http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg07046.html" rel="nofollow noreferrer"><code>pylab.figure(facecolor=SOME_COLOR, ...)</code></a> or <a href="http://matplotlib.sourceforge.net/users/customizing.html" rel="nofollow noreferrer"><code>matplotlib.rcParams['figure.facecolor'] = SOME_COLOR</code></a>. It looks like that its default value is <a href="https://github.com/matplotlib/matplotlib/blob/1cd07a6cbd1b6b25a3256463e67782bb7ff85547/lib/matplotlib/rcsetup.py#L518" rel="nofollow noreferrer">hard-coded</a>, so there is no way to tell MPL to respect GTK theme.</p> <hr> <p>Here's a concrete example of how to do this in PyGTK. Some of this information here was gleaned from <a href="https://stackoverflow.com/questions/6715464/get-colors-of-current-gtk-style">"Get colors of current gtk style"</a> and from the <a href="http://developer.gnome.org/pygtk/stable/class-gdkcolor.html" rel="nofollow noreferrer">gdk.Color</a> docs. I haven't gotten as far as setting the font, etc, but this shows the basic framework you need.</p> <p>First, define the following function:</p> <pre><code>def set_graph_appearance(container, figure): """ Given a GTK container and a Matplotlib "figure" object, this will set the figure background colour to be the same as the normal colour of the container. """ # "bg" is the background "style helper" object. It contains five different # colours, for the five different widget states. bg_style = container.get_style().bg[gtk.STATE_NORMAL] gtk_color = (bg_style.red_float, bg_style.green_float, bg_style.blue_float) figure.set_facecolor(gtk_color) </code></pre> <p>You can then connect to the <code>realize</code> signal (maybe also the <code>map-event</code> signal, I didn't try) and re-colour the graph when the containing widget is created:</p> <pre><code>graph_panel.connect('realize', set_graph_appearance, graph.figure) </code></pre> <p>(Here, <code>graph_panel</code> is a <code>gtk.Alignment</code> and <code>graph</code> is a subclass of <code>FigureCanvasGTKAgg</code> that has a <code>figure</code> member as needed.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload