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

Defining arrowprops in draggable annotation disables the pick_event #12396

Closed
@darioflute

Description

@darioflute

Bug report

Bug summary

In this interactive code, the "pick_event" is used to connect clicks on the x-label, legend's items,
and to react when the annotation is dragged. This was working up to matplotlib 2.2.3.
Since matplotlib 3.0, these behaviors are disrupted.
The problem is in the definition of the arrowprops. When I comment the line with arrowprops,
the code works again. Unfortunately, I loose the stem of the annotation.

Code for reproduction

#!/usr/bin/env pythonimportmatplotlib.pyplotaspltimportnumpyasnpdefonpick(event):print(event.artist)fig,ax=plt.subplots()fig.canvas.mpl_connect('pick_event',onpick)x=np.arange(10)blueline=ax.plot(x,x*2+10,color='blue',label='blue line')redline=ax.plot(x,np.sqrt(x),color='red',label='red line')annotation=ax.annotate("note",xy=(0.15,0.5),xytext=(0.15,0.2),xycoords='axes fraction',textcoords='axes fraction',arrowprops=dict(edgecolor='purple',alpha=0.4,arrowstyle='-')# Offending line                         )annotation.draggable()ax.set_xlabel('X',picker=True)legend=ax.legend(fancybox=True)forleglineinlegend.get_lines():legline.set_picker(5)plt.show()

Actual outcome

Traceback (most recent call last):  File "/Users/dfadda/anaconda3/lib/python3.6/site-packages/matplotlib/cbook/__init__.py", line 215, in process    func(*args, **kwargs)  File "/Users/dfadda/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 1675, in pick    self.figure.pick(mouseevent)  File "/Users/dfadda/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 447, in pick    a.pick(mouseevent)  File "/Users/dfadda/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 4141, in pick    martist.Artist.pick(self, args[0])  File "/Users/dfadda/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 447, in pick    a.pick(mouseevent)  File "/Users/dfadda/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 429, in pick    inside, prop = picker(self, mouseevent)  File "/Users/dfadda/anaconda3/lib/python3.6/site-packages/matplotlib/offsetbox.py", line 1698, in artist_picker    return self.ref_artist.contains(evt)  File "/Users/dfadda/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 2184, in contains    contains, tinfo = Text.contains(self, event)  File "/Users/dfadda/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 213, in contains    l, b, w, h = self.get_window_extent().bounds  File "/Users/dfadda/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 2359, in get_window_extent    self.update_positions(renderer)  File "/Users/dfadda/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 2215, in update_positions    self._update_position_xytext(renderer, xy_pixel)  File "/Users/dfadda/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 2298, in _update_position_xytext    pad = renderer.points_to_pixels(4)AttributeError: 'NoneType' object has no attribute 'points_to_pixels'

Expected outcome

Up to matplotlib version 2.2.3, when clicking:

  • the 'X' label

  • an item in the legend

  • the annotation 'note'

the onpick function was called and the event.artist was printed.
The annotation was also draggable.

In version 3.0, all this does not work anymore, producing the output on the screen described.
When commenting the line with "arrowprops", the previous behavior is restaured.
Unfortunately, when doing so, it is not possible to trace the connection with the note.

Matplotlib version

  • Operating system: mac osx
  • Matplotlib version: 3.0 (it was working up to version 2.2.3)
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.6
  • Jupyter version (if applicable):
  • Other libraries:

Matplotlib was installed with conda, default channel.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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