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

  • SEARCH
  • Home
  • 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 8546167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:57:18+00:00 2026-06-11T12:57:18+00:00

I am currently trying to embed a graph I want to plot in a

  • 0

I am currently trying to embed a graph I want to plot in a pyqt4 user interface I designed. As I am almost completely new to programming – I do not get how people did the embedding in the examples I found – this one (at the bottom) and that one.

It would be awesome if anybody could post a step-by-step explanation or at least a very small, very simple code only creating e.g. a graph and a button in one pyqt4 GUI.

  • 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-11T12:57:19+00:00Added an answer on June 11, 2026 at 12:57 pm

    It is not that complicated actually. Relevant Qt widgets are in matplotlib.backends.backend_qt4agg. FigureCanvasQTAgg and NavigationToolbar2QT are usually what you need. These are regular Qt widgets. You treat them as any other widget. Below is a very simple example with a Figure, Navigation and a single button that draws some random data. I’ve added comments to explain things.

    import sys
    from PyQt4 import QtGui
    
    from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
    from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
    from matplotlib.figure import Figure
    
    import random
    
    class Window(QtGui.QDialog):
        def __init__(self, parent=None):
            super(Window, self).__init__(parent)
    
            # a figure instance to plot on
            self.figure = Figure()
    
            # this is the Canvas Widget that displays the `figure`
            # it takes the `figure` instance as a parameter to __init__
            self.canvas = FigureCanvas(self.figure)
    
            # this is the Navigation widget
            # it takes the Canvas widget and a parent
            self.toolbar = NavigationToolbar(self.canvas, self)
    
            # Just some button connected to `plot` method
            self.button = QtGui.QPushButton('Plot')
            self.button.clicked.connect(self.plot)
    
            # set the layout
            layout = QtGui.QVBoxLayout()
            layout.addWidget(self.toolbar)
            layout.addWidget(self.canvas)
            layout.addWidget(self.button)
            self.setLayout(layout)
    
        def plot(self):
            ''' plot some random stuff '''
            # random data
            data = [random.random() for i in range(10)]
    
            # create an axis
            ax = self.figure.add_subplot(111)
    
            # discards the old graph
            ax.clear()
    
            # plot data
            ax.plot(data, '*-')
    
            # refresh canvas
            self.canvas.draw()
    
    if __name__ == '__main__':
        app = QtGui.QApplication(sys.argv)
    
        main = Window()
        main.show()
    
        sys.exit(app.exec_())
    

    Edit:

    Updated to reflect comments and API changes.

    • NavigationToolbar2QTAgg changed with NavigationToolbar2QT
    • Directly import Figure instead of pyplot
    • Replace deprecated ax.hold(False) with ax.clear()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying out Aptana Studio 3 for PHP development (I'm pretty new to
I'm trying to retrieve a listing of a user's youtube videos and embed them
Currently I am trying to embed a Java applet onto a webpage, and the
I'm trying to embed a VTK5 visualization inside a Qt4 window, but am not
I am currently trying to embed this project xna console in my game but
I am trying to currently embed a media player into certain web content and
We are currently trying to embed a swf into our page using https. That
Im currently trying to embed the python interpreter into my application. Because my application
Currently trying at add ajax to a site, after much reading I discovered that
Im currently trying to downlaod a audio track from a WCF, i need some

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.