dimka
dimka

Reputation: 4579

disable matplotlib toolbar

Is there a way to disable/hide matplotlib Toolbar that shows up on the bottom?

I'd tried something like this:

import matplotlib as mpl
mpl.rcParams['toolbar'] = 'None'

but unfortunately that didn't work.

Upvotes: 20

Views: 26033

Answers (5)

Paloha
Paloha

Reputation: 680

If you are in Jupyter using %matplotlib widget (ipympl) you can do:

fig.canvas.toolbar_visible = False

You can also disable header and footer with:

fig.canvas.header_visible = False
fig.canvas.footer_visible = False

Upvotes: 5

skytaker
skytaker

Reputation: 4479

Alternatively, you can hide the toolbar:

QToolBar.hide()

or

QToolBar.setVisible(False)

Obviously this will only work with a Qt backend. To expand on this answer, given the figure fig:

First, if using Qt5:

from PyQt5 import QtWidgets 

Otherwise:

from PyQt4 import QtGui as QtWidgets 

Then:

try:
    win = fig.canvas.manager.window
except AttributeError:
    win = fig.canvas.window()
toolbar = win.findChild(QtWidgets.QToolBar)
toolbar.setVisible(False)

Upvotes: 1

Erotemic
Erotemic

Reputation: 5228

To expand on bejota's answer:

Obviously this will only work with a Qt backend. To expand on this answer, given the figure fig:

First, if using Qt5:

from PyQt5 import QtWidgets 

Otherwise:

from PyQt4 import QtGui as QtWidgets 

Then:

toolbar = win.findChild(QtWidgets.QToolBar)
toolbar.setVisible(False)
try:
    win = fig.canvas.manager.window
except AttributeError:
    win = fig.canvas.window()
toolbar = win.findChild(QtWidgets.QToolBar)
toolbar.setVisible(False)

Upvotes: 0

Doughy
Doughy

Reputation: 4325

Make sure to call mpl.rcParams['toolbar'] = 'None' before you instantiate any figures.

Upvotes: 28

Vivek Saurav
Vivek Saurav

Reputation: 2275

you can go to C:\Python27\Lib\site-packages\matplotlib\mpl-data , there you will see the file named matplotlibrc, open the file and you will find a line like:

#toolbar      : toolbar2# None | toolbar2  ("classic" is deprecated)

uncomment that line and place None after the colon like:

toolbar      : None# None | toolbar2  ("classic" is deprecated) and save the file,

I guess after you can disable the toolbar in graphs plotted by matplotlib.

Upvotes: -2

Related Questions