我目前正在开发一个模拟工具的gtk / python前端。我有一切按计划工作,有一个例外 - 我无法弄清楚如何绘制与我正在显示的情节相关的颜色条。如果我没有在GTK窗口中嵌入我的绘图,我可以让colorbar显示得很好,但是一旦我嵌入它,颜色条就会消失。
相关的渲染代码(在我的python gui对象中)位于下方( init 和render_domain类函数)。我试图渲染colorbar,从render_domain函数的底部向上3行。色彩图工作正常(网格中的数据正确着色),它只是让实际的色条显示出来就是问题。想法?
class AppGui(object):
def __init__(self):
#### --- SET UP GTK INTERFACE FROM GLADE FILE --- ####
gladefile = "py_FD2D.glade"
self.windowname = "main_window"
self.builder = gtk.Builder()
self.builder.add_from_file(gladefile)
#### --- SET UP GUI SIGNALS --- ####
self.window = self.builder.get_object(self.windowname)
dic = {
"on_main_window_destroy" : self.quit,
"on_run_simulation_button_clicked" : self.run_simulation,
"on_play_button_clicked" : self.play_animation,
"on_play_slider_value_changed" : self.slider_changed,
"on_cap_pres_yn_changed" : self.cap_pres_menu_changed,
}
self.builder.connect_signals(dic)
#### --- SET UP FIGURE IN GTK WINDOW --- ####
self.figure = matplotlib.figure.Figure(figsize=(6,4), dpi=72)
self.axis = self.figure.add_subplot(1,1,1)
self.canvas = FigureCanvas(self.figure)
self.canvas.show()
self.toolbar = NavigationToolbar(self.canvas, self.window)
# Place the figure in the plot_holder pane of the py_FD2D.glade file
self.graphview = self.builder.get_object("plot_holder")
self.graphview.pack_start(self.canvas, True, True)
self.graphview.pack_start(self.toolbar, False, False)
self.FD = gcsmt.FD2D() #instantiate the simulator
self.update_all() #update all simulation parameters from gtk GUI fields
self.render_domain() #render the initial state of the plot
self.builder.get_object(self.windowname).show()
self.stop_sim = False
def render_domain(self):
self.axis.clear()
self.axis.set_xlabel('Formation Width (meters)')
self.axis.set_ylabel('Formation Thickness (meters)')
self.axis.set_title('Formation Saturation')
self.msh = matplotlib.collections.QuadMesh(self.x_cells, self.y_cells, self.verts, True)
if self.FD.HasRun()==False:
self.msh.set_array(np.zeros(self.x_cells*self.y_cells))
else:
self.msh.set_array(np.array(self.FD.GetTimestepData(0)))
self.msh.set_clim(0.0, 1.0)
self.cax = self.axis.add_collection(self.msh)
self.axis.axis([0, self.x_max, 0, self.y_top])
plt.colorbar(self.cax) ###!!! I have tried self.cax and self.msh, and various combos
self.toolbar.show()
self.canvas.draw()