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

Hi,

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

Create GUI Applications with Python & Qt5 by Martin Fitzpatrick — (PyQt5 Edition) The hands-on guide to making apps with Python — Over 10,000 copies sold!

More info Get the book

python
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
matplotlib.use("Qt5Agg")

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

        # 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>)
        layout.addWidget(toolbar)
        layout.addWidget(self.canvas)
        self.setLayout(layout)

    # 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!


Packaging Python Applications with PyInstaller by Martin Fitzpatrick — This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.

More info Get the book

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.