close gtk2 figure without main_quit() call

I am writing gtk2 application on python, I need to plot a chart in
separate window and i just use this code

    def matplot_print(self, print_values):
        """\brief print data by matplotlib and shw the figure
        \param print_values [(name - is a string, [(datetime, value)]
- is a list of data to plot)] - list of charts to plot
        """
        fig = plt.figure()
        ax = fig.add_subplot(111)
        names = map(lambda a: a[0], print_values)
        lines = map(lambda chart: ax.plot_date(map(lambda chd:
chd[0], chart[1]),
                                                map(lambda chy:
chy[1], chart[1]), '-'), print_values)
        plt.figlegend(lines, names, 'upper left')

        majloc = AutoDateLocator()
        majform = AutoDateFormatter(majloc)
        ax.xaxis.set_major_locator(majloc)
        ax.xaxis.set_major_formatter(majform)
        ax.autoscale_view()
        ax.grid(True)
        fig.autofmt_xdate()
        fig.show()

The figure is showing and everything works before closing the window
of figure. It seems that figure call gtk.main_quit() when closing it's
window. How to override this behaviour ?

I think what is happening is that matplotlib assumes that if it has to create the figure window itself, then it assumes that it has to manage the main loop itself as well. Is it possible to have the main application provide the window object for embedding the matplotlib figure within?

Ben Root

···

On Mon, Aug 1, 2011 at 2:44 PM, Alexey Uimanov <s9gf4ult@…985…> wrote:

I am writing gtk2 application on python, I need to plot a chart in

separate window and i just use this code

def matplot_print(self, print_values):

    """\brief print data by matplotlib and shw the figure

    \param print_values [(name - is a string, [(datetime, value)]
  • is a list of data to plot)] - list of charts to plot

      """
    
      fig = plt.figure()
    
      ax = fig.add_subplot(111)
    
      names = map(lambda a: a[0], print_values)
    
      lines  = map(lambda chart: ax.plot_date(map(lambda chd:
    

chd[0], chart[1]),

                                            map(lambda chy:

chy[1], chart[1]), ‘-’), print_values)

    plt.figlegend(lines, names, 'upper left')



    majloc = AutoDateLocator()

    majform = AutoDateFormatter(majloc)

    ax.xaxis.set_major_locator(majloc)

    ax.xaxis.set_major_formatter(majform)

    ax.autoscale_view()

    ax.grid(True)

    fig.autofmt_xdate()

    fig.show()

The figure is showing and everything works before closing the window

of figure. It seems that figure call gtk.main_quit() when closing it’s

window. How to override this behaviour ?