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


Python RadioButtons.set_active方法代码示例

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


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

示例1: __init__

# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import set_active [as 别名]

#.........这里部分代码省略.........
        self.radioWalkSpend.on_clicked(walkSpendChange)

        # Customization RadioButton 4: Person - Sex
        rax = plt.axes([.26, .424, .15, 0.2], axisbg=axcolor)
        rax.text(0, 1.15, "Customize Calorie Burn Info:", fontsize=11)
        rax.text(0,1.05, "Sex", fontsize=11)
        self.radioPersonSex = RadioButtons(rax, ('Male','Female'), active=0)
        def personSexChange(label):
            ''' Changes the sex of the person instance of the current instnace
            of the driver, biker, and walker objects. So much OOP!!!!'''
            if label == 'Male':
                self.d.person.setSex('M', True)
                self.b.person.setSex('M', True)
                self.w.person.setSex('M', True)
            elif label == 'Female':
                self.d.person.setSex('F', True)
                self.b.person.setSex('F', True)
                self.w.person.setSex('F', True)
            else:
                print('Error!')
            self.updateGraph()
            plt.draw()
        self.radioPersonSex.on_clicked(personSexChange)

        # Reset Button
        axReset = plt.axes([0.17, 0.25, 0.15, 0.10])
        bReset = Button(axReset, 'Reset Defaults')
        def resetDefaults(event):
            ''' Resets all buttons/sliders to their default position,
            which triggers recalculations and redrawing of the
            graphs. This function is a little slow.'''
            self.slideDist.set_val(1)
            self.slideTrip.set_val(1)
            self.radioTime.set_active(0)
            self.radioCost.set_active(0)
            self.radioCal.set_active(0)
            self.radioCO2.set_active(0)
            self.radioCarType.set_active(0)
            self.radioBikeSpend.set_active(2)
            self.radioWalkSpend.set_active(1)
            self.radioPersonSex.set_active(0)
            plt.draw()
        bReset.on_clicked(resetDefaults)

        # These keep the current drawing current.
        self.updateGraph()
        plt.show()

    def calculate(self):
        ''' This function does all the calculating behind the program. It uses
        attributes of the driver, walker, and biker object's to calculate
        values for time, cost, calorie burn, and CO2 emitted in various units.
        This information is stored in the handy-dandy dictionary: calcDict.'''

        # Dictionary that holds calculations for different categories in the form
        # of lists, where [0]=driver, [1]=biker, [2]=walker
        calcDict = {'time':[],'cost':[], 'cal':[],'time-mins':[], 'time-audio':[],
        'cost-coffee':[], 'cal-hour':[], 'cal-sansBMR':[],
        'CO2':0.0, 'CO2-tree':0.0}

        # Time in hours
        calcDict['time'].append(self.dist*self.trips / self.d.getMPH())
        calcDict['time'].append(self.dist*self.trips / self.b.getMPH())
        calcDict['time'].append(self.dist*self.trips / self.w.getMPH())

        # Cost in US dollars
开发者ID:dustinmichels,项目名称:bike-walk-drive,代码行数:70,代码来源:graphMain.py

示例2: interact2D

# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import set_active [as 别名]
def interact2D(data, xaxis=0, yaxis=1, channel=0, local=False, verbose=True):
    """ Interactive 2D plot of the dataset.
    Side plots show x and y projections of the slice (shaded gray).
    Left clicks on the main axes draw 1D slices on side plots at the coordinates selected.
    Right clicks remove the 1D slices.
    For 3+ dimensional data, sliders below the main axes are used to change which slice is viewed.

    Parameters
    ----------
    data : WrightTools.Data object
        Data to plot.
    xaxis : string, integer, or data.Axis object (optional)
        Expression or index of x axis. Default is 0.
    yaxis : string, integer, or data.Axis object (optional)
        Expression or index of y axis. Default is 1.
    channel : string, integer, or data.Channel object (optional)
        Name or index of channel to plot. Default is 0.
    local : boolean (optional)
        Toggle plotting locally. Default is False.
    verbose : boolean (optional)
        Toggle talkback. Default is True.
    """
    # avoid changing passed data object
    data = data.copy()
    # unpack
    channel = get_channel(data, channel)
    for ch in data.channel_names:
        if ch != channel.natural_name:
            data.remove_channel(ch, verbose=False)
    varis = list(data.variable_names)
    for ax in data.axes:
        for v in ax.variables:
            try:
                varis.remove(v.natural_name)
            except ValueError:
                pass  # Already removed, can't double count
    for v in varis:
        data.remove_variable(v, implied=False, verbose=False)
    xaxis, yaxis = get_axes(data, [xaxis, yaxis])
    cmap = get_colormap(channel)
    current_state = Bunch()
    # create figure
    nsliders = data.ndim - 2
    if nsliders < 0:
        raise DimensionalityError(">= 2", data.ndim)
    # TODO: implement aspect; doesn't work currently because of our incorporation of colorbar
    fig, gs = create_figure(width="single", nrows=7 + nsliders, cols=[1, 1, 1, 1, 1, "cbar"])
    # create axes
    ax0 = plt.subplot(gs[1:6, 0:5])
    ax0.patch.set_facecolor("w")
    cax = plt.subplot(gs[1:6, -1])
    sp_x = add_sideplot(ax0, "x", pad=0.1)
    sp_y = add_sideplot(ax0, "y", pad=0.1)
    ax_local = plt.subplot(gs[0, 0], aspect="equal", frameon=False)
    ax_title = plt.subplot(gs[0, 3], frameon=False)
    ax_title.text(
        0.5,
        0.5,
        data.natural_name,
        fontsize=18,
        horizontalalignment="center",
        verticalalignment="center",
        transform=ax_title.transAxes,
    )
    ax_title.set_axis_off()
    # NOTE: there are more axes here for more buttons / widgets in future plans
    # create lines
    x_color = "#00BFBF"  # cyan with saturation increased
    y_color = "coral"
    line_sp_x = sp_x.plot([None], [None], visible=False, color=x_color)[0]
    line_sp_y = sp_y.plot([None], [None], visible=False, color=y_color)[0]
    crosshair_hline = ax0.plot([None], [None], visible=False, color=x_color)[0]
    crosshair_vline = ax0.plot([None], [None], visible=False, color=y_color)[0]
    current_state.xpos = crosshair_hline.get_ydata()[0]
    current_state.ypos = crosshair_vline.get_xdata()[0]
    current_state.bin_vs_x = True
    current_state.bin_vs_y = True
    # create buttons
    current_state.local = local
    radio = RadioButtons(ax_local, (" global", " local"))
    if local:
        radio.set_active(1)
    else:
        radio.set_active(0)
    for circle in radio.circles:
        circle.set_radius(0.14)
    # create sliders
    sliders = {}
    for axis in data.axes:
        if axis not in [xaxis, yaxis]:
            if axis.size > np.prod(axis.shape):
                raise NotImplementedError("Cannot use multivariable axis as a slider")
            slider_axes = plt.subplot(gs[~len(sliders), :]).axes
            slider = Slider(slider_axes, axis.label, 0, axis.points.size - 1, valinit=0, valstep=1)
            sliders[axis.natural_name] = slider
            slider.ax.vlines(
                range(axis.points.size - 1),
                *slider.ax.get_ylim(),
                colors="k",
                linestyle=":",
#.........这里部分代码省略.........
开发者ID:wright-group,项目名称:WrightTools,代码行数:103,代码来源:_interact.py


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