Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Unable to plot
QtWS25 Last Chance

Unable to plot

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 3 Posters 407 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ALI-
    wrote on 13 Mar 2023, 07:16 last edited by
    #1

    from PyQt5.QtWidgets import *

    from matplotlib.backends.backend_qt5agg import FigureCanvasAgg as FigureCanvas

    from matplotlib.figure import Figure

    class MplWidget(QWidget):

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
    
        self.canvas = FigureCanvas(Figure())
    
        vertical_layout = QVBoxLayout()
        vertical_layout.addWidget(self.canvas)
    
        self.canvas.axes = self.canvas.figure.add_subplot(111)
        self.setLayout(vertical_layout)
    

    from PyQt5.QtWidgets import *
    from PyQt5.uic import loadUi

    from matplotlib.backends.backend_qt5agg import (NavigationToolbar2QT as NavigationToolbar)

    import numpy as np
    import random

    class MatplotlibWidget(QMainWindow):

    def __init__(self):
        QMainWindow.__init__(self)
    
        loadUi(r"C:\Users\Mehidiali Agharia\PycharmProjects\pythonProject\GUI_1.ui", self)
    
        self.setWindowTitle("PyQt5 & Matplotlib Example GUI")
    
        self.pushButton.clicked.connect(self.update_graph)
    
        self.addToolBar(NavigationToolbar(self.MplWidget.canvas, self))
    
    def update_graph(self):
        fs = 500
        f = random.randint(1, 100)
        ts = 1 / fs
        length_of_signal = 100
        t = np.linspace(0, 1, length_of_signal)
    
        cosinus_signal = np.cos(2 * np.pi * f * t)
        sinus_signal = np.sin(2 * np.pi * f * t)
    
        self.MplWidget.canvas.axes.clear()
        self.MplWidget.canvas.axes.plot(t, cosinus_signal)
        self.MplWidget.canvas.axes.plot(t, sinus_signal)
        self.MplWidget.canvas.axes.legend(('cosinus', 'sinus'), loc='upper right')
        self.MplWidget.canvas.axes.set_title('Cosinus - Sinus Signal')
        self.MplWidget.canvas.draw()
    

    app = QApplication([])
    window = MatplotlibWidget()
    window.show()
    app.exec_()

    J 1 Reply Last reply 13 Mar 2023, 07:20
    0
    • A ALI-
      13 Mar 2023, 07:16

      from PyQt5.QtWidgets import *

      from matplotlib.backends.backend_qt5agg import FigureCanvasAgg as FigureCanvas

      from matplotlib.figure import Figure

      class MplWidget(QWidget):

      def __init__(self, parent=None):
          QWidget.__init__(self, parent)
      
          self.canvas = FigureCanvas(Figure())
      
          vertical_layout = QVBoxLayout()
          vertical_layout.addWidget(self.canvas)
      
          self.canvas.axes = self.canvas.figure.add_subplot(111)
          self.setLayout(vertical_layout)
      

      from PyQt5.QtWidgets import *
      from PyQt5.uic import loadUi

      from matplotlib.backends.backend_qt5agg import (NavigationToolbar2QT as NavigationToolbar)

      import numpy as np
      import random

      class MatplotlibWidget(QMainWindow):

      def __init__(self):
          QMainWindow.__init__(self)
      
          loadUi(r"C:\Users\Mehidiali Agharia\PycharmProjects\pythonProject\GUI_1.ui", self)
      
          self.setWindowTitle("PyQt5 & Matplotlib Example GUI")
      
          self.pushButton.clicked.connect(self.update_graph)
      
          self.addToolBar(NavigationToolbar(self.MplWidget.canvas, self))
      
      def update_graph(self):
          fs = 500
          f = random.randint(1, 100)
          ts = 1 / fs
          length_of_signal = 100
          t = np.linspace(0, 1, length_of_signal)
      
          cosinus_signal = np.cos(2 * np.pi * f * t)
          sinus_signal = np.sin(2 * np.pi * f * t)
      
          self.MplWidget.canvas.axes.clear()
          self.MplWidget.canvas.axes.plot(t, cosinus_signal)
          self.MplWidget.canvas.axes.plot(t, sinus_signal)
          self.MplWidget.canvas.axes.legend(('cosinus', 'sinus'), loc='upper right')
          self.MplWidget.canvas.axes.set_title('Cosinus - Sinus Signal')
          self.MplWidget.canvas.draw()
      

      app = QApplication([])
      window = MatplotlibWidget()
      window.show()
      app.exec_()

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 13 Mar 2023, 07:20 last edited by
      #2

      @ALI

      1. Please format your code properly!
      2. Ask a clear question and describe what is not working (we are not mind readers)

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ALI-
        wrote on 13 Mar 2023, 08:58 last edited by
        #3

        'MatplotlibWidget' object has no attribute 'MplWidget'

        this type of error is coming
        can you please help me ?

        J J 2 Replies Last reply 13 Mar 2023, 09:07
        0
        • A ALI-
          13 Mar 2023, 08:58

          'MatplotlibWidget' object has no attribute 'MplWidget'

          this type of error is coming
          can you please help me ?

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 13 Mar 2023, 09:07 last edited by jsulm
          #4

          @ALI You asked exact same question in another thread and got an answer already.
          Please don't double post!

          The error message is quite clear: your MatplotlibWidget has no member called MplWidget. Why should it have such a member?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • A ALI-
            13 Mar 2023, 08:58

            'MatplotlibWidget' object has no attribute 'MplWidget'

            this type of error is coming
            can you please help me ?

            J Online
            J Online
            JonB
            wrote on 13 Mar 2023, 09:23 last edited by JonB
            #5

            @ALI
            What is the point of you asking this question in another post, I answered it there, now you ask here... ? This is why double-posting is unhelpful.

            1 Reply Last reply
            0

            1/5

            13 Mar 2023, 07:16

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved