Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple y-scales but only one enabled for pan and zoom

Consider the following python code for plotting a matplotlib figure:

import matplotlib.pylab as pp
import numpy as np

alpha = np.linspace(0, 2 * np.pi, 400)
sig1 = np.sin(alpha)
sig2 = np.sin(2 * alpha) + 2 * (alpha > np.pi)

ax1 = pp.subplot(111)
ax2 = ax1.twinx()

ax1.plot(alpha, sig1, color='b')
ax2.plot(alpha, sig2, color='r')
ax1.set_ylabel('sig1 value', color='b')
ax2.set_ylabel('sig2 value', color='r')
pp.grid()
pp.show()

Giving me a nice plot

enter image description here

I would like to find out how to disable one of the axes for panning / zooming, so when I use the pan / zoom tool, only ax2 will rescale for example. Is there a way to do this? I want to do it programmatically.

like image 572
Tompa Avatar asked Mar 08 '13 21:03

Tompa


1 Answers

You can do this using ax2.set_navigate(False):

from matplotlib.pyplot import *
import numpy as np

fig,ax1 = subplots(1,1)
ax2 = ax1.twinx()
ax2.set_navigate(False)
x = np.linspace(0,2*np.pi,100)
ax1.plot(x,np.sin(x),'b')
ax1.set_xlabel('Scaleable axis')
ax1.set_ylabel('Scaleable axis')
ax2.plot(x,np.sin(x+1),'r')
ax2.set_ylabel('Static axis',weight='bold')
like image 58
ali_m Avatar answered Nov 03 '22 17:11

ali_m