在 Python Spyder 交互式绘图中。如何链接图,以便当我放大一个图中的一个图时,它将同一图和不同图上的所有其他图缩放到相同的比例?它们都是随时间绘制的,时间为毫秒。
这是我目前仍在开发中的代码示例。 (我知道我在两次绘制同一件事,我只是在测试一些东西。)
import numpy as np
import matplotlib.pyplot as plt
data = np.loadtxt('data'.csv', delimiter=',', skiprows=1)
# This uses array slicing/indexing to cut the correct columns into variables.
mSec = data[:,0]
Airspeed = data[:,10]
AS_Cmd = data[:,25]
airspeed = data[:,3]
plt.rc('xtick', labelsize=15) #increase xaxis tick size
plt.rc('ytick', labelsize=15) #increase yaxis tick size
# Create a figure figsize = ()
fig1 = plt.figure(figsize= (20,20))
ax = fig1.add_subplot(211)
ax.plot(mSec, Airspeed, label='Ground speed [m/s]', color = 'r')
ax.plot(mSec, AS_Cmd, label='AS_Cmd')
plt.legend(loc='best',prop={'size':13})
ax.set_ylim([-10,40])
ax1 = fig1.add_subplot(212)
ax1.plot(mSec, Airspeed, label='Ground speed [m/s]', color = 'r')
ax1.plot(mSec, AS_Cmd, label='AS_Cmd[m/s]')
# Show the legend
plt.legend(loc='lower left',prop={'size':8})
fig1.savefig('trans2.png', dpi=(200), bbox_inches='tight') #borderless on save
请您参考如下方法:
sharex 和 sharey 是你的 friend 。 最小示例:
import numpy as np
import matplotlib.pyplot as plt
fig1, (ax1, ax2) = plt.subplots(1,2,sharex=True, sharey=True)
ax1.plot(np.random.rand(10))
ax2.plot(np.random.rand(11))
fig2 = plt.figure()
ax3 = fig2.add_axes([0.1, 0.1, 0.8, 0.8], sharex=ax1, sharey=ax1)
ax3.plot(np.random.rand(12))
