Python matplotlib.widgets 模块,Slider() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用matplotlib.widgets.Slider()

项目:planetplanet    作者:rodluger    | 项目源码 | 文件源码
def __init__(self, **kwargs):
        '''

        '''

        self.kwargs = kwargs
        self.fig = pl.figure(figsize = (6,6))
        self.fig.subplots_adjust(bottom = 0.25)
        self.axtheta = pl.axes([0.3, 0.05, 0.44, 0.03])
        self.theta = Slider(self.axtheta, r'$\theta$', -180., 180., 
                            valinit = 90.)
        self.axphi = pl.axes([0.3, 0.1, 0.44, 0.03])
        self.phi = Slider(self.axphi, r'$\Phi$', -90, 90., valinit = 0.)
        self.axlam = pl.axes([0.3, 0.15, 0.44, 0.03])
        self.lam = Slider(self.axlam, r'$\Lambda$', -90, 90., valinit = 0.)
        self.theta.on_changed(self._update)
        self.phi.on_changed(self._update)
        self.lam.on_changed(self._update)
        self._update(90.)
        pl.show()
项目:planetplanet    作者:rodluger    | 项目源码 | 文件源码
def _test():
    '''

    '''

    # HACK: Python 2 does not seem to like the Slider widget...
    import sys
    if sys.version_info[0] < 3:
        return

    plot()
    pl.show()
项目:planetplanet    作者:rodluger    | 项目源码 | 文件源码
def plot():
    '''

    '''

    fig, ax = pl.subplots(1)
    ax.axis('off')
    fig.subplots_adjust(bottom = 0.2)

    z = np.zeros((100, 100)) * np.nan
    img = pl.imshow(z, cmap = cmap, vmin = 0, vmax = 180., 
                    extent = (-1, 1, -1, 1))
    x = np.linspace(-0.99,0.99,1000)
    ax.plot(x, np.sqrt(0.99 ** 2 - x ** 2), 'k-', lw = 2)
    ax.plot(x, -np.sqrt(0.99 ** 2 - x ** 2), 'k-', lw = 2)
    ax.set_xlim(-1.1,1.1)
    ax.set_ylim(-1.1,1.1)

    axslider = pl.axes([0.3, 0.05, 0.44, 0.03])
    slider = Slider(axslider, r'$\theta$', -180., 180., valinit = 45.)

    def update(val):
        theta = slider.val
        for i, x in enumerate(np.linspace(-1,1,100)):
            for j, y in enumerate(np.linspace(-1,1,100)):
                if (x ** 2 + y ** 2 <= 1):
                    z[j,i] = ZenithAngle(x, y, 1, theta * np.pi / 180) \
                             * 180 / np.pi
        img.set_data(z)
        fig.canvas.draw_idle()

    slider.on_changed(update)
    update(45.)
项目:kite    作者:pyrocko    | 项目源码 | 文件源码
def interactive(self):
        """Simple interactive quadtree plot with matplot

        This is a relictic function
        """
        from matplotlib.widgets import Slider
        self._initImagePlot()

        def change_epsilon(e):
            self._quadtree.epsilon = e

        def close_figure(*args):
            self._quadtree.evChanged.unsubscribe(self._update)

        self.ax.set_position([0.05, 0.15, 0.90, 0.8])
        ax_eps = self.fig.add_axes([0.05, 0.1, 0.90, 0.03])

        self.data = self._quadtree.leaf_matrix_means
        self.title = 'Quadtree Means - Interactive'

        self._addInfoText()

        epsilon = Slider(ax_eps, 'Epsilon',
                         self._quadtree.epsilon - 1.*self._quadtree.epsilon,
                         self._quadtree.epsilon + 1.*self._quadtree.epsilon,
                         valinit=self._quadtree.epsilon, valfmt='%1.3f')

        # Catch events
        epsilon.on_changed(change_epsilon)
        self._quadtree.evChanged.subscribe(self._update)
        self.fig.canvas.mpl_connect('close_event', close_figure)

        plt.show()
项目:qtbroker    作者:NSLS-II    | 项目源码 | 文件源码
def __init__(self, viewer, images):
        self.viewer = viewer
        self.images = images
        length = len(self.images)
        fig = self.viewer._fig
        slider_ax = fig.add_axes([0.1, 0.01, 0.8, 0.02])
        self.slider = Slider(slider_ax, 'Frame', 0, length - 1, 0,
                             valfmt='%d/{}'.format(length - 1))
        self.slider.on_changed(self.update)
        self.update(0)  # Trigger the initialization of viewer.