-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the toolbar customizable #270
Comments
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 |
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. |
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. |
That would be really nice! Would make it super easy to customize, and maybe rearrange (move buttons around into different containers, etc..) |
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 |
@martinRenou that's a great idea! |
👍 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 |
Yes I tried those methods but the functionality is not available with |
In case you want to remove buttons from the toolbar, it seems that you can do this by changing the list of import matplotlib.pyplot as plt
%matplotlib widget
fig, ax = plt.subplots()
items = fig.canvas.toolbar.toolitems
new_tools = [items[0], items[3], items[4], items[5]]
fig.canvas.toolbar.toolitems = new_tools
fig.canvas So in combination with my workaround above, i'm able to almost completely customize my toolbar. |
Yes indeed, I forgot about this :) This is actually Matplotlib API if I am correct. |
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 The other methods are |
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 So this is the result: import matplotlib.pyplot as plt
import ipywidgets as ipw
fig, ax = plt.subplots()
ax.plot(np.random.rand(100))
plt.ioff()
fig.canvas.toolbar_visible = False
new_toolbar = ipw.VBox([fig.canvas.toolbar, ipw.Button(icon='clipboard', layout={"width": "34px"})])
ipw.HBox([new_toolbar, fig.canvas]) |
The following works for me, extending the "native" toolbar instead of creating a new one: def update_graph(*args, **kwargs):
# do some stuff with the figure and call draw_idle()
fig.canvas.toolbar.update_graph = update_graph
fig.canvas.toolbar.toolitems = [*fig.canvas.toolbar.toolitems,
("Update", "Update the Graph", "refresh", "update_graph")]
fig.canvas.toolbar_visible = 'visible' pip freeze
|
Hi,
Is it possible to add custom buttons to the toolbar?
Many thanks for any help.
The text was updated successfully, but these errors were encountered: