我想使用滑块功能在等高线图上滑动垂直,并想要绘制该x值的数据 . 可以在我的程序中使用滑块功能更新数据但我无法使用滑块功能更新或移动垂直线 . image is attached for your reference where red line i want to slide along x axis你可以说我有两个子图,一个子图有轮廓图,其他图将绘制线图 . 当我更改滑块位置时,我的垂直线位置也需要相应地更改,但我无法执行此任务 . 任何人都可以帮助我如何执行此任务 .
import numpy as np
from pylab import genfromtxt;
from matplotlib.widgets import Slider, Button, RadioButtons
from matplotlib.colors import colorConverter
import matplotlib.cm as cm
import matplotlib.pyplot as plt
mat0 = genfromtxt('C:\Python27\countarray.txt');
count=np.asarray(mat0)
r1=count.shape[0] # row data unique no
c1=count.shape[1] # column data time value
print "r1=" , r1, "c1 =" ,c1
time=np.arange(0,c1,1) # time data ( in sec)
unique=np.arange(0,r1,1) # energy information
axcolor = 'lightgoldenrodyellow'
delta_f = 1.0
fig2=plt.figure()
fig2.add_subplot(111)
plt.imshow(count)
plt.show()
fig1=plt.figure()
fig1.add_subplot(211)
plt.pcolor(time,unique.T,count,cmap=cm.coolwarm)
t, = plt.plot([time[1],time[1]],
[unique.T[0],unique.T[-1]],lw=2, color='red')
fig1.add_subplot(212)
l, = plt.plot(unique*2.004, count[:,1], lw=2,
color='red')
axamp = plt.axes([0.25, 0.02, 0.50, 0.03],
f acecolor=axcolor)
axle = plt.axes([0.25, 0.02, 0.50, 0.03],
facecolor=axcolor)
lin1 = Slider(axle, 'Time (ms)', time[0], time[-1],
valinit=10,valstep=delta_f)
samp= Slider(axamp, 'Time (ms)', time[0], time[-1],
valinit=10,valstep=delta_f)
def update(val):
amp = samp.val
#lin2=lin1.val
#t.set_ydata([time[int(amp)],time[int(amp)]],
[unique.T[0],unique.T[-1]],lw=2, color='red')
l.set_ydata(count[:,int(amp)])
fig1.canvas.draw_idle()
samp.on_changed(update)
lin1.on_changed(update)
plt.show()