根据主轴设置双轴位置

时间:2014-09-26 08:39:02

标签: python python-2.7 matplotlib plot

我有这个情节,其中第二个斧头是通过fig.main_axe.twinx()创建的。我想要的是将它的下边界设置为相应的主oY ax零点,同时保持自动缩放。 请查看图片以便更好地理解。 Example 以下是一个例子:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 10, 0.005)
y = np.exp(-x/2.) * np.sin(2*np.pi*x)
y_2 = np.cos(2*np.pi*x)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.spines['bottom'].set_position(('data', 0))
ax.plot(x, y)

ax_other = ax.twinx()
# Somehow I want this cos(x) to be plotted above the oY=0 line
# while still keeping y values from [-1;1]
ax_other.plot(x,y_2)

plt.show()

对于这个例子,我希望cos(x)根据主轴在I和II quarters中绘制。或者换句话说,我希望-1孪生(右)斧从主(左)斧的0点开始。

0 个答案:

没有答案