当前位置: 首页>>代码示例>>Python>>正文


Python Slider.drawon方法代码示例

本文整理汇总了Python中matplotlib.widgets.Slider.drawon方法的典型用法代码示例。如果您正苦于以下问题:Python Slider.drawon方法的具体用法?Python Slider.drawon怎么用?Python Slider.drawon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.widgets.Slider的用法示例。


在下文中一共展示了Slider.drawon方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: slide_phantom

# 需要导入模块: from matplotlib.widgets import Slider [as 别名]
# 或者: from matplotlib.widgets.Slider import drawon [as 别名]
def slide_phantom(shot, camera='phantom2', sub=20, blur=3, interval=50, 
                  pixel_t_hist=None):
    """
    Slide through Phantom frames while displaying last closed flux surface and 
    relevant timeseries plots.
    Parameters
        shot: int, shot number
        camera: string e.g. 'phantom' (outboard midplane GPI),
                'phantom2' (X-point GPI)
        sub: number of frames to use in average subtraction. 20 works well.
        blur: extent of Gaussian blur, 1, 2, or 3 advisable
        interval: delay in ms between frames during play
        pixel_t_hist: (x,y) to show time history of that pixel instead of 
        H-alpha.
    """
    time = acquire.gpi_series(shot, camera, 'time')
    frames = acquire.video(shot, camera)
    frame_count = frames.shape[0]
    
    # Plot GPI and LCFS 
    gs = gridspec.GridSpec(3, 1, height_ratios=[3, 1, 1])
    fig, ax = plt.subplots()
    plt.subplots_adjust(bottom=0.25, hspace=.43, top=.96)
    plt.subplot(gs[0])
    im = plt.imshow(frames[0], origin='lower', cmap=plt.cm.gist_heat)
    plt.colorbar()
    plt.axis('off')

    # Plot H_alpha or pixel timeseries
    plt.subplot(gs[1]).locator_params(axis='y', nbins=4)
    if pixel_t_hist:
        plt.title('Pixel time history')
        plt.plot(time, 
                 frames[:, pixel_t_hist[0], pixel_t_hist[1]].swapaxes(0, 1))
    else: 
        plt.title('H-alpha')
        time_ha2, ha2 = process.time_crop(acquire.time_ha2(shot), time)
        plt.plot(time_ha2, ha2)
    vl1 = plt.axvline(time[0], color='r')
    plt.xlim([time[0], time[-1]])

    # Plot line average density 
    time_dens, dens = process.time_crop(acquire.time_dens(shot), time) 
    plt.subplot(gs[2]).locator_params(axis='y', nbins=4)
    plt.title('Line Average Density')
    plt.plot(time_dens, dens)
    vl2 = plt.axvline(time[0], color='r')
    plt.xlabel('Time (s)')
    plt.xlim([time[0], time[-1]])

    curr_frame = 0

    def update(val):
        global frames, curr_frame
        val = int(val)
        curr_frame = val 
        curr_time = time[val]
        slider.valtext.set_text('%d (t=%.5f s)' % (val, curr_time))
        if val < frame_count: 
            im.set_array(frames[val])
            vl1.set_xdata(curr_time)
            vl2.set_xdata(curr_time)
        fig.canvas.draw_idle()
 
    # Slider settings
    slide_area = plt.axes([0.10, 0.1, 0.65, 0.03])
    slider = Slider(slide_area, 'Frame', 0, frame_count-1, valinit=0)
    slider.drawon = True
    slider.valfmt = '%d'
    slider.on_changed(update)

    def init():
        global curr_frame
        curr_frame = int(curr_frame)
        start_frame = curr_frame
        im.set_data(frames[curr_frame])
        vl1.set_xdata(time[curr_frame])
        vl2.set_xdata(time[curr_frame])
        for i in xrange(curr_frame, curr_frame + 200, 1): 
            slider.set_val(i)
            vl1.set_xdata(time[i])
            vl2.set_xdata(time[i])
        slider.set_val(start_frame)
        return [im, vl1, vl2]

    def animate(i):
        im.set_array(frames[i])
        vl1.set_xdata(time[i])
        vl2.set_xdata(time[i])
        return [im, vl1, vl2]
    
    def play(event):
        anim = animation.FuncAnimation(fig, animate, init_func=init,
                                       frames=100, interval=interval, 
                                       blit=False)

    def forward(event):
        global curr_frame
        slider.set_val(curr_frame + 1)

#.........这里部分代码省略.........
开发者ID:sballin,项目名称:phantom_viewer,代码行数:103,代码来源:view.py

示例2: slide_corr

# 需要导入模块: from matplotlib.widgets import Slider [as 别名]
# 或者: from matplotlib.widgets.Slider import drawon [as 别名]
def slide_corr(frames, pixel, other_pixels=None):
    """
    Display correlation values for a pixel with a slider for lag time.
    Parameters
        frames: NumPy array of correlations with dimension (no. lags, x pixels,
                y pixels)
        pixel: (x, y) to mark with a circle
        other_pixels: array of (x, y) values of pixels to mark
    """
    frame_count = frames.shape[0]

    # Initial plotting
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    plt.subplots_adjust(bottom=0.25)
    im = plt.imshow(frames[frame_count/2], origin='bottom', 
                    cmap=plt.cm.RdBu_r, vmin=-1, vmax=1)
    circ = plt.Circle(pixel[::-1], radius=1, edgecolor='r', fill=False)
    ax.add_patch(circ)
    if other_pixels: 
        t_hists_r = [o[0] for o in other_pixels]
        t_hists_z = [o[1] for o in other_pixels]
    else:
        t_hists_r = acquire.gpi_series(1150611004, 'phantom2', 'hist_xpix')
        t_hists_z = acquire.gpi_series(1150611004, 'phantom2', 'hist_ypix')
    for pos in zip(t_hists_r, t_hists_z): 
        ax.add_patch(plt.Circle(pos, radius=1, edgecolor='b', fill=False))
    plt.colorbar()
    plt.title('Correlation for pixel (%d, %d)' % pixel)
    plt.xlabel('Pixel y coordinate')
    plt.ylabel('Pixel x coordinate')

    # Slider and button settings
    slide_area = plt.axes([0.10, 0.1, 0.65, 0.03])
    slider = Slider(slide_area, 'Lag', -frame_count/2, frame_count/2, valinit=0)
    slider.drawon = True
    slider.valfmt = '%d'
    play_button_area = plt.axes([0.45, 0.025, 0.1, 0.04])
    play_button = Button(play_button_area, 'Play')

    curr_frame = 0

    def update(val):
        global curr_frame
        curr_frame = val + frame_count/2
        slider.valtext.set_text('%d' % val)
        if curr_frame < frame_count: 
            im.set_array(frames[curr_frame])
        fig.canvas.draw_idle()

    slider.on_changed(update)

    def init():
        global curr_frame
        curr_frame = int(curr_frame)
        im.set_data(frames[curr_frame])
        for i in xrange(curr_frame, curr_frame + 200, 2): 
            slider.set_val(i)
        return [im]

    def animate(i):
        im.set_array(frames[i])
        return [im]
    
    def play(event):
        anim = animation.FuncAnimation(fig, animate, init_func=init, frames=
                                       frame_count, interval=0, blit=False)

    play_button.on_clicked(play)
    plt.show()
开发者ID:sballin,项目名称:phantom_viewer,代码行数:72,代码来源:view.py


注:本文中的matplotlib.widgets.Slider.drawon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。