Reputation: 532
I'm trying to remove all toolbar buttons except 'save' button. I managed to remove the buttons but I couldn't find a way to remove the 'Configure subplots' button.
Here is a simple code just to illustrate how i tried to remove the buttons:
import matplotlib.pyplot as plt
plt.rcParams['toolbar'] = 'toolmanager'
# I managed to find the buttons' names while reading the backend_bases.py
# I didn't find the subplot configuration button name so i didn't include it here
buttons_names = ['forward', 'back', 'pan', 'zoom', 'home', 'help']
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([1, 2], [1, 2])
# removing buttons using
for button in buttons_names:
fig.canvas.manager.toolmanager.remove_tool(button)
plt.show()
I looked at backend_bases.py and commented the subplots tuple which now looks like this: (I don't know if there is a reference to 'subplots configuration' button somewhere else in order to remove the button)
toolitems = (
('Home', 'Reset original view', 'home', 'home'),
('Back', 'Back to previous view', 'back', 'back'),
('Forward', 'Forward to next view', 'forward', 'forward'),
(None, None, None, None),
('Pan', 'Pan axes with left mouse, zoom with right', 'move', 'pan'),
('Zoom', 'Zoom to rectangle', 'zoom_to_rect', 'zoom'),
#('Subplots', 'Configure subplots', 'subplots', 'configure_subplots'),
(None, None, None, None),
('Save', 'Save the figure', 'filesave', 'save_figure'),
)
Also when i run the code above, it also shows a warning:
UserWarning: Treat the new Tool classes introduced in v1.5 as experimental for now, the API will likely change in version 2.1, and some tools might change name
'experimental for now, the API will likely change in ' +
I looked at other solutions but none worked for me, and some of them use gui frameworks which is not what i'm looking for.
Is there any other way that can remove the button, or is there a name for subplots configuration button that i can include in the buttons_names
list in the code above?
Update: Ok, it seems that the problem was associated with python version. I was using python 3.7.0. I updated to 3.7.4, added 'subplots'
to buttons_names
list and it worked. But there are 2 issues:
Treat the new Tool classes introduced in v1.5 as experimental for now, the API will likely change in version 2.1 and perhaps the rcParam as well
C:/Users/usr/Documents/MyPrograms/Python/Daily Expense/Chart.py:36: UserWarning: The new Tool classes introduced in v1.5 are experimental; their API (including names) will likely change in future versions.
fig = plt.figure()
Currently i'm using Python 3.7.4, matplotlib version 3.1.1, Windows 10
How can i fix these 2 things?
Upvotes: 1
Views: 1819
Reputation: 2897
Re part 1 of your question, I've been able to suppress that annoying warning by doing this:
import sys
import matplotlib.pyplot as plt
if not sys.warnoptions:
import warnings
warnings.filterwarnings("ignore", category=UserWarning,
message="Treat the new Tool classes introduced in v1.5 as experimental for now")
plt.rcParams['toolbar'] = 'toolmanager'
You may have to edit the value of the message
arg if the warning message changes with later matplotlib versions though. See the Python docs for the Warnings Filter.
Upvotes: 0
Reputation: 326
Apparently the name is "subplots":
fig.canvas.manager.toolmanager.remove_tool("subplots")
Upvotes: 3