Matplotlib not taking whole of the window

Heads up! You've already completed this tutorial.

Patrick_Raphael | 2020-05-07 19:31:57 UTC | #1

In this case you make the matplotlib figure take up the entire window, replacing the central widget. This means you cannot use QtDesigner to add UI controls and would have to do it all by hand.

Is there any way to embed just the axes in a Qt widget such as GraphicsView? While matplotlib figures are designed to use the whole window, a single axis could just use one widget. You can do this with pyqtgraph ( a diffent plotting library), but I'm not sure if its possible with matplotlib.

https://www.pythonguis.com/courses/graphics-plotting/plotting-matplotlib/


martin | 2020-05-07 19:36:46 UTC | #2

@Patrick_Raphael the matplotlib canvas is just a normal QWidget onto which the plot is drawn. That means you can do anything with it you can with a normal widget.

If you would like to build your UI in Qt Designer you have two options --

  • Use "promote" to place a matplotlib widget (based on a QWidget) in Qt Designer this tutorial for embedding PyQtGraph will explain how (the process isn't PyQtGraph specific)
  • Build your layout except for the plot in Qt Designer and then place just that from your code

Using Qt Designer doesn't prevent you from also writing normal layout code, it just pre-generates a bunch for you.

Does that help?


Over 10,000 developers have bought Create GUI Applications with Python & Qt!

To support developers in [[ countryRegion ]] I give a [[ localizedDiscount[couponCode] ]]% discount with the code [[ couponCode ]] — Enjoy!

For [[ activeDiscount.description ]] I'm giving a [[ activeDiscount.discount ]]% discount with the code [[ couponCode ]] — Enjoy!

Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak