Skip to content

Pick_event on AnnotationBbox fires at wrong position #16946

@VagosGrigoropoulos

Description

@VagosGrigoropoulos

Hitting a pick event on artists works fine until ,axes zoom.Then you can random click in map and then the changed position artist will trigger pick event.

Change the image in my code to any image about 50x50 and zoom to map.
P.S.Disconnect and reimplement mpl signal doesnt work.

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from PIL import Image
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
import numpy as np
import random



def on_pick(event):
    if event.mouseevent.button == 1 and isinstance(event.artist, AnnotationBbox) == True and event.artist.get_gid() != None:

        artist = event.artist
        pid = artist.get_gid()
        print(pid)


figure,ax = plt.subplots(1)
m = Basemap(projection='cyl',llcrnrlat=-90,urcrnrlat=90,\
        llcrnrlon=-180,urcrnrlon=180,lat_ts=20,resolution='c')
m.drawmeridians(np.arange(0,360,30))
m.drawparallels(np.arange(-90,90,10)) 
m.drawmapboundary(fill_color='aqua')
m.fillcontinents(color='coral',lake_color='aqua')
#### rundom coordinates ####
list_random = []
for i in range (0,400):
    x = random.randrange(-180, 180)
    y = random.randrange(-90, 90)
    list_random.append([x,y])

id = 0 
airport = np.array(Image.open('test_alt.png'))### change here for any small image
for i in list_random:
    im = OffsetImage(airport,zoom = 0.22)
    ab = AnnotationBbox(im, (float(i[0]),float(i[1])), xycoords='data',frameon=False)
    ab.set_gid(id)
    ab.set_picker(0.1)
    ab.set_transform(ax.transData)
    ab.set_clip_on(False)
    ax.add_artist(ab)
    id+=1

pick = figure.canvas.mpl_connect('pick_event',on_pick)
plt.show()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions