disable matplotlib toolbar

社会主义新天地 提交于 2019-12-12 08:47:30

问题


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.


回答1:


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




回答2:


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)



回答3:


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.




回答4:


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)


来源:https://stackoverflow.com/questions/13942956/disable-matplotlib-toolbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!