Size of Matplotlib's navigation toolbar (too large by default compared to the other widgets)

Heads up! You've already completed this tutorial.

nael | 2020-11-04 07:14:06 UTC | #1


I'm plotting data stored in a Pandas dataframe as a Matplotlib graph with a Matplotlib toolbar, as explained in chapter 36 of the PySide2 book.

The toolbar's controls appear to have the same height as a QPushButton. Despite that, they appear really large compared to the rest of the interface, perhaps also because of their stronger black color. Is there any way to make them, say, the same height as a default line of text for instance?

Ideally I'd love to see them as a semi-transparent overlay on the graph's canvas itself, as they do in recent versions of MATLAB. But I haven't found any hint in the Matplotlib documentation that this might be possible.

Here is my current implementation of the graph in the following window:

Screenshot 2020-11-03 161239|416x500

import matplotlib  # PySide2 imports done before matplotlib's
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure

class PlotterWidget(QWidget):
    def __init__(self):

        # Create three "plot" QPushButton widgets

        # Create a maptlotlib FigureCanvas object,
        # which defines a single set of axes as its axes attribute
        self.canvas = MplCanvas(self, width=5, height=3, dpi=100)

        # Create toolbar for the figure:
        # * First argument: the canvas that the toolbar must control
        # * Second argument: the toolbar's parent (self, the PlotterWidget)
        toolbar = NavigationToolbar(self.canvas, self)

        # Define and apply widget layout
        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addLayout(<sublayout of three "plot" QPushButton here>)

    # def slot methods for the three "plot" QPushButtons

logcbl211714 | 2021-07-23 14:34:56 UTC | #2

Hi, i'm also looking for a solution to control the size of the toolbar. Have you found any fix ?

Thanks !

nael | 2021-08-16 22:50:59 UTC | #3

Hi @logcbl211714, sadly I haven't made any progress on this issue as it's not been a priority issue. I remain interested in finding a way to fix that unsightly toolbar, though. Let me know if you find anything!

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

Size of Matplotlib's navigation toolbar (too large by default compared to the other widgets) 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.