You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We could actually redesign the current Toolbar as being a bunch of ipywidgets Buttons in a VBox, so that it's easier remove buttons or add new ones in Python.
Reacted by Thomas Aarholt, sdbbs and Jerome Kieffer
which gives me
So when I use the folding button, my new button is still there, but that's no big deal for me as I hardly ever use the fold button anyway.
Now my question is how can I display the new_toolbar, next to the plot?
I was trying to put the new_toolbar and the plot inside a HBox but i can't seem to get the plot only (without the toolbar) as a widget. Any pointers?
We could actually redesign the current Toolbar as being a bunch of ipywidgets Buttons in a VBox, so that it's easier remove buttons or add new ones in Python.
That would be really nice! Would make it super easy to customize, and maybe rearrange (move buttons around into different containers, etc..)
Now my question is how can I display the new_toolbar, next to the plot?
I was trying to put the new_toolbar and the plot inside a HBox but i can't seem to get the plot only (without the toolbar) as a widget. Any pointers?
There might not be a clean way of doing it in the current state of ipympl. But you might be able to hack around it by setting the plot's canvas.toolbar_visible flag to False, then put your extended toolbar inside an HBox with your plot.
We could actually redesign the current Toolbar as being a bunch of ipywidgets Buttons in a VBox, so that it's easier remove buttons or add new ones in Python.
Yes I tried those methods but the functionality is not available with ipympl. The api is not exactly the same. And using the ipywidgets api seems much cleaner and makes more sense when the canvas is itself a widget.
In addition, I have another workaround if you wish to customize either the appearance of the buttons in the original mpl toolbar, or their behaviour.
I can replace them with custom icons by just hiding the toolbar entirely, and add for example a custom "Home" button with any icon I want, and inside my callback I can call the original matplotlib fig.canvas.toolbar.home() function, and any other additional methods of my choosing.
The other methods are zoom(), pan(), save_figure() etc...
@martinRenou that's a great idea! I agree it's not super clean, but it's at least very simple and works: Thanks!
Many thanks for the nice idea! Unfortunately, I think it does not work like this anymore. If the toolbar is toogled invisible, it stays invisible when adding it to the VBox. So it's not possible to add a Button to the toolbar like that, only next to the actual toolbar.
The following works for me, extending the "native" toolbar instead of creating a new one:
defupdate_graph(*args, **kwargs):
# do some stuff with the figure and call draw_idle()fig.canvas.toolbar.update_graph=update_graphfig.canvas.toolbar.toolitems= [*fig.canvas.toolbar.toolitems,
("Update", "Update the Graph", "refresh", "update_graph")]
fig.canvas.toolbar_visible='visible'
All the information here was very helpful for me to customize the toolbar. I needed to do a few more things like having a button that behaves more like pan & zoom (creates a new state), etc...
Activity
martinRenou commentedon Oct 9, 2020
Hi,
It's not possible, although you could definitely use ipywidgets and create a Button and a container for both your button and your plot
thomasaarholt commentedon Oct 9, 2020
This is something that would be quite nice to add - if it isn't that hard. We were talking about it over at the hyperspy repo in the last year.
martinRenou commentedon Oct 9, 2020
It might not be too difficult I guess.
We could actually redesign the current Toolbar as being a bunch of ipywidgets Buttons in a VBox, so that it's easier remove buttons or add new ones in Python.
nvaytet commentedon Oct 9, 2020
Thanks.
I have managed to create a button, and put the toolbar and the button inside a
VBox.which gives me


So when I use the folding button, my new button is still there, but that's no big deal for me as I hardly ever use the fold button anyway.
Now my question is how can I display the
new_toolbar, next to the plot?I was trying to put the
new_toolbarand the plot inside aHBoxbut i can't seem to get the plot only (without the toolbar) as a widget. Any pointers?Thanks!
nvaytet commentedon Oct 9, 2020
That would be really nice! Would make it super easy to customize, and maybe rearrange (move buttons around into different containers, etc..)
martinRenou commentedon Oct 9, 2020
There might not be a clean way of doing it in the current state of ipympl. But you might be able to hack around it by setting the plot's
canvas.toolbar_visibleflag toFalse, then put your extended toolbar inside an HBox with your plot.nvaytet commentedon Oct 9, 2020
@martinRenou that's a great idea!

I agree it's not super clean, but it's at least very simple and works:
Thanks!
ianhi commentedon Oct 9, 2020
👍 to this. It also may make sense to keep in mind that matplotlib does have methods for modifying the toolbar. https://matplotlib.org/3.3.0/gallery/user_interfaces/toolmanager_sgskip.html
nvaytet commentedon Oct 9, 2020
Yes I tried those methods but the functionality is not available with
ipympl. The api is not exactly the same. And using theipywidgetsapi seems much cleaner and makes more sense when the canvas is itself a widget.[-]How to edit/customize the toolbar?[/-][+]Make the toolbar customizable[/+]nvaytet commentedon Oct 29, 2020
In case you want to remove buttons from the toolbar, it seems that you can do this by changing the list of
toolitems:yields

So in combination with my workaround above, i'm able to almost completely customize my toolbar.
martinRenou commentedon Oct 29, 2020
Yes indeed, I forgot about this :) This is actually Matplotlib API if I am correct.
nvaytet commentedon Dec 2, 2020
In addition, I have another workaround if you wish to customize either the appearance of the buttons in the original mpl toolbar, or their behaviour.
I can replace them with custom icons by just hiding the toolbar entirely, and add for example a custom "Home" button with any icon I want, and inside my callback I can call the original matplotlib
fig.canvas.toolbar.home()function, and any other additional methods of my choosing.The other methods are
zoom(),pan(),save_figure()etc...scimax commentedon Jul 9, 2024
Many thanks for the nice idea! Unfortunately, I think it does not work like this anymore. If the toolbar is toogled invisible, it stays invisible when adding it to the
VBox. So it's not possible to add a Button to the toolbar like that, only next to the actual toolbar.So this is the result:
N-Coder commentedon Jul 22, 2024
The following works for me, extending the "native" toolbar instead of creating a new one:
pip freeze
MatthieuLJ commentedon Jan 9, 2026
All the information here was very helpful for me to customize the toolbar. I needed to do a few more things like having a button that behaves more like pan & zoom (creates a new state), etc...
So if that's helpful to anyone, here is my code: https://gist.github.com/MatthieuLJ/98798c4d641b6d1979570962617765c8
(Comments are also much welcome if I'm doing something wrong or missing anything)