i'm writing pygtk/twisted app uses matplotlib graphing. it's easy enough embed plots in widgets using figurecanvasgtkagg, notice background colour of canvas (outside plot area itself) not match rest of application, , neither font (for labels, legends, etc).
is there simple way graphs respect user selected gtk theme?
you can set by, example pylab.figure(facecolor=some_color, ...) or matplotlib.rcparams['figure.facecolor'] = some_color. looks default value hard-coded, there no way tell mpl respect gtk theme.
here's concrete example of how in pygtk. of information here gleaned "get colors of current gtk style" , gdk.color docs. haven't gotten far setting font, etc, shows basic framework need.
first, define following function:
def set_graph_appearance(container, figure): """ given gtk container , matplotlib "figure" object, set figure background colour same normal colour of container. """ # "bg" background "style helper" object. contains 5 different # colours, 5 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) you can connect realize signal (maybe map-event signal, didn't try) , re-colour graph when containing widget created:
graph_panel.connect('realize', set_graph_appearance, graph.figure) (here, graph_panel gtk.alignment , graph subclass of figurecanvasgtkagg has figure member needed.)
Comments
Post a Comment