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: #16220 doubled pick events for subclassed figure with a button #19610

Closed
@larsoner

Description

@larsoner

Bug report

Pick events are fired twice instead of once following#16220. This example is a bit wacky, but it's the minimal version of amuch more complete GUI:

# -*- coding: utf-8 -*-importnumpyasnpfrommatplotlib.figureimportFigurefrommatplotlib.textimportTextimportmatplotlib# noqafrommatplotlib.pyplotimportfigurefrommatplotlib.widgetsimportButtonfrommpl_toolkits.axes_grid1.axes_sizeimportFixedfrommpl_toolkits.axes_grid1.axes_dividerimportmake_axes_locatable# matplotlib.use('Agg', force=True)classFigure1(Figure):"""Interactive figure with scrollbars, for data browsing."""def__init__(self,yticks,**kwargs):super().__init__(figsize=(6,6))ax_main=self.add_subplot(1,1,1,position=[0.1,0.1,0.9,0.9])div=make_axes_locatable(ax_main)ax_button=div.append_axes(position='bottom',size=Fixed(0.5),pad=0)self._button=Button(ax_button,'Help')# main plotoffsets=np.arange(len(yticks))ax_main.set(xlim=[0,1],yticks=offsets)ax_main.set_yticklabels(yticks,picker=True)ax_main.plot([0,1], [offsets,offsets])picked=list()defon_pick(event):"""Handle matplotlib pick events."""ifisinstance(event.artist,Text):ch_name=event.artist.get_text()print(f'pick{ch_name}')picked.append(ch_name)yticks=list(x*5forxin'ABCD')fig=figure(FigureClass=Figure1,yticks=yticks)fig.canvas.mpl_connect('pick_event',on_pick)fig.canvas.draw()ax=fig.axes[0]x,y=ax.transData.transform_point((-0.1,0))func=fig.canvas.button_press_event(x=x,y=y,button=1,guiEvent=None)assert'AAAAA'inpickedassertlen(picked)==1,len(picked)

If you click on a ylabel (or simulate this with the code above), you get two pick events instead of one.

Screenshot from 2021-03-01 12-06-30

Actual outcome

On6d79e6e / after#16220:

pick AAAAApick AAAAATraceback (most recent call last):  File "/home/larsoner/Desktop/fig.py", line 52, in <module>    assert len(picked) == 1, len(picked)AssertionError: 2

Expected outcome

On74d6145 / before#16220:

pick AAAAA

Matplotlib version

  • Matplotlib version (import matplotlib; print(matplotlib.__version__)):6d79e6e or later
  • Matplotlib backend (print(matplotlib.get_backend())): Tested on Qt5Agg and Agg
  • Python version: 3.9.0

cc@anntzer since it was your PR that seems to have caused this.

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