2

I am plotting a figure with matplotlib using the following code. I have two stacked subplots, as well as a added second x axis using twiny.

#!/usr/bin/python
import os
import numpy as np
import matplotlib.pylab as mp

# random data
data = np.random.random((10,3)) 
data[:,0] = np.linspace(0,1,10)

# init figure
fig, axs = mp.subplots(2, sharex=True)
axs = np.append(axs,axs[1].twiny())

# plot top
axs[0].plot(data[:,0],data[:,1],'bo-',linewidth=2.0)
axs[0].axis([data[0,0],data[-1,0],data[:,1].min(),data[:,1].max()])

# plot bottom
axs[1].plot(data[:,0],data[:,2],'rx-',linewidth=2.0)

# add second axis
axs[2].xaxis.set_ticks_position('bottom')
axs[2].xaxis.set_label_position('bottom')
axs[2].spines['bottom'].set_position(('outward', 40))
axs[2].set_xlim(-180,180)

# plot
mp.tight_layout(pad=0.6)
mp.show()

My problem is in the interactive plot window: if I pan the lower plot, all 3 x-axes move accordingly. If I pan the top plot, the added twiny axis does not move. Would this be possible in the current set up?

Markus
  • 1,215
  • 1
  • 12
  • 19

0 Answers0