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?


The complete guide to packaging Python GUI applications with PyInstaller.
[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]
Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

Matplotlib not taking whole of the window was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.