[Python] matplotlib: How to pick up shift click on figure?

Discussão em 'Python' iniciado por Stack, Agosto 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have a matplotlib and I have created a button_press_event like this:

    self.fig.canvas.mpl_connect('button_press_event', self.onClick)

    def onClick(self, event)
    if event.button == 1:
    # draw some artists on left click

    elif event.button == 2:
    # draw a vertical line on the mouse x location on wheel click

    elif event.button == 3:
    # clear artists on right click


    Now is it possible to modify the wheel click handler to something like this

    elif event.button == 2 or (event.button == 1 and event.key == "shift"):
    # draw a vertical line on the mouse x location
    # on wheel click or on shift+left click
    # (alternative way if there is no wheel for example)


    It seems that button_press_event doesn't support keys and key_press_event doesn't support mouse button clicks, but I'm not sure.

    Is there a way?

    Continue reading...

Compartilhe esta Página