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

Draggable legend with use_blit hides legend after legend picking [Bug]: #28129

Open
@dallas74

Description

@dallas74

Bug summary

Using the legend picking example (https://matplotlib.org/stable/gallery/event_handling/legend_picking.html) and changing the next last line from leg.set_draggable(True) to leg.set_draggable(True, use_blit=True) then legend is not showing after picking it. Clicking again over its position makes it visible again.
Setting the legend draggable again (after being picked/clicked) with use_blit=False does not help.
Best regards, Daniel

Code for reproduction

# https://matplotlib.org/stable/gallery/event_handling/legend_picking.htmlimportmatplotlib.pyplotaspltimportnumpyasnpt=np.linspace(0,1)y1=2*np.sin(2*np.pi*t)y2=4*np.sin(2*np.pi*2*t)fig,ax=plt.subplots()ax.set_title('Click on legend line to toggle line on/off')(line1, )=ax.plot(t,y1,lw=2,label='1 Hz')(line2, )=ax.plot(t,y2,lw=2,label='2 Hz')leg=ax.legend(fancybox=True,shadow=True)lines= [line1,line2]map_legend_to_ax= {}# Will map legend lines to original lines.pickradius=5# Points (Pt). How close the click needs to be to trigger an event.forlegend_line,ax_lineinzip(leg.get_lines(),lines):legend_line.set_picker(pickradius)# Enable picking on the legend line.map_legend_to_ax[legend_line]=ax_linedefon_pick(event):# On the pick event, find the original line corresponding to the legend# proxy line, and toggle its visibility.legend_line=event.artist# Do nothing if the source of the event is not a legend line.iflegend_linenotinmap_legend_to_ax:returnax_line=map_legend_to_ax[legend_line]visible=notax_line.get_visible()ax_line.set_visible(visible)# Change the alpha on the line in the legend, so we can see what lines# have been toggled.legend_line.set_alpha(1.0ifvisibleelse0.2)fig.canvas.draw()fig.canvas.mpl_connect('pick_event',on_pick)# Works even if the legend is draggable. This is independent from picking legend lines.leg.set_draggable(True,use_blit=True)plt.show()

Actual outcome

The legend is not showing after picking it. Clicking again over its position makes it visible again.

Expected outcome

Legend is visible at all times.

Additional information

No response

Operating system

Windows

Matplotlib Version

3.8.1

Matplotlib Backend

TkAgg

Python version

3.9.7

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp