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?
Press the right mouse button to zoom, dragging it to a new position. The x axis will be zoomed in proportionately to the rightward movement and zoomed out proportionately to the leftward movement. The same is true for the y axis and up/down motions.
Matplotlib can be used in an interactive or non-interactive modes. In the interactive mode, the graph display gets updated after each statement. In the non-interactive mode, the graph does not get displayed until explicitly asked to do so.
The python plotting library matplotlib will by default add margins to any plot that it generates. They can be reduced to a certain degree through some options of savefig() , namely bbox_inches='tight' and pad_inches=0 .
and the matplotlib. artist. Artist is the object that knows how to use a renderer to paint onto the canvas.
You can also bind a key press and key release events and do something like:
self.fig.canvas.mpl_connect('key_press_event', self.on_key_press)
self.fig.canvas.mpl_connect('key_release_event', self.on_key_release)
...
def on_key_press(self, event):
if event.key == 'shift':
self.shift_is_held = True
def on_key_release(self, event):
if event.key == 'shift':
self.shift_is_held = False
Then you can check in your onClick
function if self.shift_is_held
.
if event.button == 3:
if self.shift_is_held:
do_something()
else:
do_something_else()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With