Skip to content
Advertisement

Matplotlib lock ylim so it can’t be adjusted while panning in UI

I have subplots whose ylims I want to keep locked, so I can scroll through them using matplotlib’s UI. I just want to pan through in the x direction, but sometimes I accidentally pan up/down so that the data pans off screen. Here is an example of an oops:

panning disaster

What can I do so this doesn’t happen? I set the ylims programmatically, and that sets them up fine initially , but doesn’t stop me from panning accidentally:

JavaScript

Is there a way to lock those ylims in place so I can’t pan the data off the axes?

Advertisement

Answer

Basically you could hold the x key during the pan.

A solution doing that automatically for your plot based on a combination of two other answers:
simonb answer on atplotlib forcing pan/zoom to constrain to x-axes
ajdawson answer on How do I change matplotlib’s subplot projection of an existing axis?

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement