I’m writing a PyGTK/Twisted app that uses Matplotlib for graphing. It’s easy enough to embed the plots in my widgets using the FigureCanvasGtkAgg, but I notice that the background colour of the canvas (outside the plot area itself) does not match that for the rest of my application, and neither does the font (for labels, legends, etc).
Is there a simple way to get my graphs to respect the user selected GTK theme?
You can set it by, for example
pylab.figure(facecolor=SOME_COLOR, ...)ormatplotlib.rcParams['figure.facecolor'] = SOME_COLOR. It looks like that its default value is hard-coded, so there is no way to tell MPL to respect GTK theme.Here’s a concrete example of how to do this in PyGTK. Some of this information here was gleaned from “Get colors of current gtk style” and from the gdk.Color docs. I haven’t gotten as far as setting the font, etc, but this shows the basic framework you need.
First, define the following function:
You can then connect to the
realizesignal (maybe also themap-eventsignal, I didn’t try) and re-colour the graph when the containing widget is created:(Here,
graph_panelis agtk.Alignmentandgraphis a subclass ofFigureCanvasGTKAggthat has afiguremember as needed.)