多个 y 尺度,但只有一个启用平移和缩放 [英] Multiple y-scales but only one enabled for pan and zoom

查看:32
本文介绍了多个 y 尺度,但只有一个启用平移和缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下用于绘制 matplotlib 图的 Python 代码:

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

我想了解如何禁用平移/缩放轴之一,因此当我使用平移/缩放工具时,例如只有 ax2 会重新缩放.有没有办法做到这一点?我想以编程方式进行.

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.

推荐答案

您可以使用 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')

这篇关于多个 y 尺度,但只有一个启用平移和缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆