Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed
Labels
Milestone
Description
Bug summary
Prior tomatplotlib 3.6
, I was able to use an icon for a custom tool in the toolbar of a figure which had aLA
mode (see attached). Now I can't seem to be able to load it anymore as a custom icon.
Code for reproduction
importosimportmatplotlibmatplotlib.rcParams["toolbar"]="toolmanager"importmatplotlib.pyplotaspltfrommatplotlib.backend_toolsimportToolToggleBaseclassCustomTool(ToolToggleBase):image=os.path.join(os.path.dirname(__file__),"icon.png")if__name__=="__main__":fig=plt.figure()toolmanager=fig.canvas.manager.toolmanagertoolbar=fig.canvas.manager.toolbartoolmanager.add_tool("custom",CustomTool)toolbar.add_tool("custom","group")
Actual outcome
/home/[...]/mwe.py:4: UserWarning: Treat the new Tool classes introduced in v1.5 as experimental for now; the API and rcParam may change in future versions. matplotlib.rcParams["toolbar"] = "toolmanager"Traceback (most recent call last): File "/home/[...]/mwe.py", line 19, in <module> toolbar.add_tool("custom", "group") File "/home/[...]/lib/python3.10/site-packages/matplotlib/backend_bases.py", line 3377, in add_tool self.add_toolitem(tool.name, group, position, File "/home/[...]/lib/python3.10/site-packages/matplotlib/backends/_backend_tk.py", line 957, in add_toolitem button = NavigationToolbar2Tk._Button(frame, name, image_file, toggle, File "/home/[...]/lib/python3.10/site-packages/matplotlib/backends/_backend_tk.py", line 792, in _Button NavigationToolbar2Tk._set_image_for_button(self, b) File "/home/[...]/lib/python3.10/site-packages/matplotlib/backends/_backend_tk.py", line 734, in _set_image_for_button im_alt = _recolor_icon(im, foreground) File "/home/[...]/lib/python3.10/site-packages/matplotlib/backends/_backend_tk.py", line 722, in _recolor_icon image_data[black_mask, :3] = colorValueError: shape mismatch: value array of shape (3,) could not be broadcast to indexing result of shape (0,2)
Expected outcome
No errors should be raised and the icon should be displayed in the toolbar.
Additional information
Downgrading tomatplotlib v 3.5.3
solves the issue. Don't know why this happens, but icons that have aRGBA
mode (like the default icons) don't seem to have this problem. The attached icon has aLA
mode.
Operating system
Ubuntu 22.04
Matplotlib Version
3.6.3
Matplotlib Backend
TkAgg
Python version
3.10.6
Jupyter version
N/A
Installation
pip