Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9251173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:37:50+00:00 2026-06-18T10:37:50+00:00

My program (developed with GTK using glade ) receives some data and has the

  • 0

My program (developed with GTK using glade) receives some data and has the option to display a seperate window containing a matplotlib scatterplot that represents the data.

My problem is that if the user closes the graph window and reopens it, no graph is displayed. It is just a blank GTK Window. I’m sure there is a simple fix, but there aren’t many resources available that are relevant to my issue (or GTK and matlplotlib integration for that matter).

I have created a Module for my scatterplot so I can easily reuse it. I am just trying to get it to work, so the code isn’t structured perfectly.

##Scatterplot Module:

import gtk
import matplotlib
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
from matplotlib.figure import Figure


class ScatterPlot:
    def __init__(self):
       self.window = gtk.Window()
       self.window.connect("destroy", lambda x: self.destroy())
       self.window.set_default_size(500,400)
       self.is_hidden = False

       self.figure = Figure(figsize = (5,4), dpi=100)
       self.ax = self.figure
       self.ax = self.ax.add_subplot(111)
       self.canvas = FigureCanvas(self.figure)
       self.window.add(self.canvas)

       self.Xs = list()
       self.Ys = list()

   def set_axis(self, xLimit = (0,384) , yLimit = (0,100)):
       self.ax.set_xlim(xLimit)
       self.ax.set_ylim(yLimit)

   def plot(self, xs, ys):
       self.Xs.extend([xs])
       self.Ys.extend([ys])
       self.ax.plot(xs,ys,'bo')

   def update(self):
       self.window.add(self.canvas)

   def set_title(self, title):
       self.ax.set_title(title)

   def show(self):
       self.window.show_all()
       self.is_hidden = False

   def hide(self):
       self.window.hide()
       self.is_hidden = True

   def destroy(self):
       self.window.destroy()

I call the module like so:

class GUI:
    def __init__(self):
        self.scatterplot = scatterplot.ScatterPlot()

        #When the user presses the "Graph" button it calls the following function
    def graph():
        self.scatterplot.plot(someDataX, someDataY)
        self.scatterplot.set_axis()
        self.scatterplot.set_title("Some Title")
        self.scatterplot.show()

(This was just an example of what my code looks like.)

When the scatterplot is closed, I am calling self.window.destroy instead of self.window.hide. When reopening is attempted, I call the same graph() function but, as stated above, the GTK Window does not display the graph. (When I first open it, it displays perfectly)

My speculations:

  • Should I be calling .hide() instead of .destroy()?
  • Is there a piece of code in scatterplot‘s constructor that needs to be called again to create the plot?
  • Or should I just re-instantiate the plot every time graph() is called?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:37:51+00:00Added an answer on June 18, 2026 at 10:37 am

    My Solution:

    From:

    class ScatterPlot:
        def __init__(self):
            #remove the following two lines
            self.canvas = FigureCanvas(self.figure)
            self.window.add(self.canvas)
    

    Move the two lines of code to show()

    def show(self):
        self.canvas = FigureCanvas(self.figure)
        self.window.add(self.canvas)
        self.window.show_all()
        self.is_hidden = False
    

    Moving these two lines of code allows the graph to be displayed when re-opening the window.

    Sidenote: Calling both .destroy() or .show() when closing the window will work. I’m not sure which one is better though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a VB.NET program using a strongly typed dataset. This dataset has
I've developed a program using Delphi that, among some features, does a lot of
I have a program developed and it has a single entry point. A Try
I developed a program to draw polygon triangles. The triangles were drawn using mouse
I have developed the following program/architecture: A) A Java servlet receives POST requests, gets
So I developed a UI in Glade and am coding the program in Python.
I have a program developed under java with netbeans. It has a text pane
I'm using MonoDevelop tool. I want to make program like below with GTK#; 1.
I am using C# 2008 SP1 I developed a program that will be run
I developed a WPF application using XML as the database file. Yesterday, the program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.