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. QT6 and matplotlib
Forum Updated to NodeBB v4.3 + New Features

QT6 and matplotlib

Scheduled Pinned Locked Moved Solved Qt for Python
5 Posts 2 Posters 1.3k 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.
  • G Offline
    G Offline
    GaryN
    wrote on last edited by
    #1

    I am now adding a matplotlib graph to my system.

    From my understanding, I need to drag and drop on a QWidget; which will contain my plot.

    I have then followed a series of instructions on producing matplotlib graphs; all of which have worked fine.

    However, these all use the idea of building the form items (a QWidget) and then setting this as the central widget (self.setCentralWidget(sc))

    Obviously, I have dropped a QWidget onto my form and want the plot to appear within that object.

    Using the working examples I have, I get to the following point:

    sc = MplCanvas(self, width=5, height=4, dpi=100)
    sc.axes.plot([0, 1, 2, 3, 4], [10, 1, 20, 3, 40])
    widget = self.window.findChild(QWidget, 'plotWidget')
    

    The form runs without issue or warnings but, obviously, the QWidget (named plotWidget on the form) does not appear and nothing appears inside: I haven't assigned sc to it yet.

    How do I do this assignment?
    Or am I on the wrong track?

    JonBJ 1 Reply Last reply
    0
    • G GaryN

      I am now adding a matplotlib graph to my system.

      From my understanding, I need to drag and drop on a QWidget; which will contain my plot.

      I have then followed a series of instructions on producing matplotlib graphs; all of which have worked fine.

      However, these all use the idea of building the form items (a QWidget) and then setting this as the central widget (self.setCentralWidget(sc))

      Obviously, I have dropped a QWidget onto my form and want the plot to appear within that object.

      Using the working examples I have, I get to the following point:

      sc = MplCanvas(self, width=5, height=4, dpi=100)
      sc.axes.plot([0, 1, 2, 3, 4], [10, 1, 20, 3, 40])
      widget = self.window.findChild(QWidget, 'plotWidget')
      

      The form runs without issue or warnings but, obviously, the QWidget (named plotWidget on the form) does not appear and nothing appears inside: I haven't assigned sc to it yet.

      How do I do this assignment?
      Or am I on the wrong track?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @GaryN
      I have never used Matplotlib. If I understand you right. You want to put an MplCanvas()-runtime-generated object, which is a QWidget, onto a form you have designed.

      So you can do any of:

      • Just addWidget(sc) somewhere in the desired place. You don't need a QWidget placeholder on the form at design-time.

      • Replace the design-time added QWidget with your sc (you may have to removeWidget(yourWidget)).

      • Retain your design-time added QWidget. At runtime add e.g. a QHBoxLayout onto that widget, and then addWidget(sc) onto that layout.

      G 2 Replies Last reply
      0
      • JonBJ JonB

        @GaryN
        I have never used Matplotlib. If I understand you right. You want to put an MplCanvas()-runtime-generated object, which is a QWidget, onto a form you have designed.

        So you can do any of:

        • Just addWidget(sc) somewhere in the desired place. You don't need a QWidget placeholder on the form at design-time.

        • Replace the design-time added QWidget with your sc (you may have to removeWidget(yourWidget)).

        • Retain your design-time added QWidget. At runtime add e.g. a QHBoxLayout onto that widget, and then addWidget(sc) onto that layout.

        G Offline
        G Offline
        GaryN
        wrote on last edited by
        #3

        @JonB

        I really appreciate your help on all of this. :)

        From your three suggestions, I get the sense that building the form as I have been is possibly the wrong way?

        Anyway, just sticking to this situation at present. I did have the addWidget(sc) aspect, but how do I define it's (x, y) position on the existing form?

        I have a QTabWidget with (currently) 2 tabs. How do I direct the addWidget to ensure it goes within the right tab?

        1 Reply Last reply
        0
        • JonBJ JonB

          @GaryN
          I have never used Matplotlib. If I understand you right. You want to put an MplCanvas()-runtime-generated object, which is a QWidget, onto a form you have designed.

          So you can do any of:

          • Just addWidget(sc) somewhere in the desired place. You don't need a QWidget placeholder on the form at design-time.

          • Replace the design-time added QWidget with your sc (you may have to removeWidget(yourWidget)).

          • Retain your design-time added QWidget. At runtime add e.g. a QHBoxLayout onto that widget, and then addWidget(sc) onto that layout.

          G Offline
          G Offline
          GaryN
          wrote on last edited by
          #4

          @JonB

          Ah, I just re-read your third bulletpoint and initially got it wrong!

          Yes, that might work; since all the examples I have make the sc widget be the central widget; and that QWidget would then sit exactly where I wanted it, with the matplotlib object residing inside exactly as my example copies have it in the single window!

          Am I coorect in my interpretation there?

          JonBJ 1 Reply Last reply
          0
          • G GaryN

            @JonB

            Ah, I just re-read your third bulletpoint and initially got it wrong!

            Yes, that might work; since all the examples I have make the sc widget be the central widget; and that QWidget would then sit exactly where I wanted it, with the matplotlib object residing inside exactly as my example copies have it in the single window!

            Am I coorect in my interpretation there?

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #5

            @GaryN
            Well it puts it wherever you tell it to put it. If you put it in the centre of something that's where it will appear. Give it a try and see.

            1 Reply Last reply
            0

            • Login

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