简体   繁体   中英

In Python Spyder interactive plotting. How do I link plots so that when I zoom in on a plot it zooms in on the rest

In Python Spyder interactive plotting. How do I link plots so that when I zoom in on one plot in one figure, it zooms all the other plots that are on the same figure and different figure to the same scale? They are all plotted vs time which is mSec.

Here is a sample of my current code that is still in the works. (I know I am plotting the same thing twice, I am just testing few things.)

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 and sharey are your friends. Minimal example:

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM