1

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.

enter image description here

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:

  1. When the chart is shown, it displays a warning:
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()
  1. The toolbar is now shown on top, it used to be under the chart and i want to make it display under the chart as it used to.

Currently i'm using Python 3.7.4, matplotlib version 3.1.1, Windows 10

How can i fix these 2 things?

3
  • 1
    what system and what version of Python and Matplotlib do you use ? subplots" removes this button on Linux Mint 19.2, Python 3.7.4, matplotlib 3.1.1. It seems it removes button for other users too. So maybe it depends on versions or system. Commented Aug 26, 2019 at 21:33
  • I've updated the question and provided the info about what version i'm using Commented Aug 27, 2019 at 7:53
  • this is a duplicate of stackoverflow.com/questions/55779944/… Commented Sep 7, 2023 at 11:26

2 Answers 2

3

Apparently the name is "subplots":

fig.canvas.manager.toolmanager.remove_tool("subplots")
Sign up to request clarification or add additional context in comments.

1 Comment

That is exactly why i asked the question in the first place, I tried the name 'subplots' but it the program catches an exception: AttributeError: 'NoneType' object has no attribute 'destroy'. As i've said in the question that i commented the 'subplots' tuple in toolitems, I uncommented the tuple and reran the script but still catches the AttributeError exception.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.