Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: LA image mode not working anymore for custom toolbar buttons #25164

Closed
Milestone
@fgoudreault

Description

@fgoudreault

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.
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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp