如何在嵌入matplotlib的gtk / glade窗口中绘制颜色栏?

问题描述

| 我目前正在研究gtk / python仿真工具的前端。我已按计划进行了所有工作,但有一个例外-我无法弄清楚如何绘制与要显示的图相关的颜色条。如果我不将绘图嵌入GTK窗口中,我可以使颜色条显示得很好,但是一旦我将其嵌入,颜色条就会消失。 相关的渲染代码(在我的python gui对象中)在下面(init和render_domain类函数)。我正在尝试渲染颜色条,从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,self.y_top])
    plt.colorbar(self.cax)  ###!!! I have tried self.cax and self.msh,and varIoUs combos
    self.toolbar.show()
    self.canvas.draw()
    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)