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 8262577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:48:00+00:00 2026-06-08T03:48:00+00:00

I have a Python program to plot a simple graph in using a custom

  • 0

I have a Python program to plot a simple graph in using a custom matplotlib widget.
My code is as follows:

import sys
from GUI import *
import random
import matplotlib.pyplot as plt

class GUIForm(QtGui.QDialog):

    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self,parent)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)

        QtCore.QObject.connect(self.ui.pushButton,
                               QtCore.SIGNAL('clicked()'), self.PlotFunc)

    def PlotFunc(self):
        randValList = random.sample(range(0, 10), 10)
        print(randValList)
        self.ui.PlotWidget.canvas.ax.clear()
        self.ui.PlotWidget.canvas.ax.plot(randValList)

    def callFunc(self):
        myapp.PlotFunc()


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = GUIForm()
    myapp.show()
    sys.exit(app.exec_())

When I run the program I can see the GUI but when I click the button the plot does not show the line. The empty plot is visible.
However if I dO

def __init__(self, parent=None):
            QtGui.QWidget.__init__(self,parent)
            self.ui = Ui_Dialog()
            self.ui.setupUi(self)

            QtCore.QObject.connect(self.ui.pushButton,
                                   QtCore.SIGNAL('clicked()'), self.PlotFunc)
            self.ui.PlotWidget.canvas.ax.plot(randValList)

or

if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        myapp = GUIForm()
        myapp.show()
        self.PlotFunc()
        sys.exit(app.exec_())

the program draws the graph.
So I’m guessing it has to do with sys.exit(app.exec_()) but do not know how to fix this.
Any help is appreciated.

Thank you.

  • 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-08T03:48:01+00:00Added an answer on June 8, 2026 at 3:48 am

    By any chance, does it work if you add this line at the end of PlotFunc?

    self.ui.PlotWidget.canvas.draw()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python program that generates a histogram using matplotlib. The problem is
I have a working Python 2.6 code using matplotlib, and would like to get
I have a python program which takes input from stdin. Now, I've to write
I have a python program that imports pythoncom (and uses pythoncom.CoCreateInstance from it). I
I have a python program that does something like this: Read a row from
I have written a python program with a PyQt GUI that, using the imaplib,
I have a Python program for Linux almost looks like this one : import
I have a python program running using a parallel python. This module scales my
I have a python program that I would like to present as a simple
I'm trying to extract some data from various HTML pages using a python 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.