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


Python ipywidgets.interact方法代码示例

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


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

示例1: metal_distance_widget

# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import interact [as 别名]
def metal_distance_widget(df_concat):
    '''Plot an violinplot of metal-element distances with ipywidgets

    Parameters
    ----------
    df_concat : Dataframe
       dataframe of metal-elements distances

    '''
    metals = df_concat['Metal'].unique().tolist()
    m_widget = Dropdown(options = metals, description = "Metals")

    def metal_distance_violinplot(metal):
        df_metal = df_concat[df_concat["Metal"] == metal].copy()
        df_metal['Element'] = df_metal['Element'].apply(lambda x: metal+"-"+x)

        # Set fonts
        fig, ax = plt.subplots()
        fig.set_size_inches(15,6)
        subplot = sns.violinplot(x="Element", y="Distance", palette="muted", data=df_metal, ax=ax)
        subplot.set(xlabel="Metal Interactions", ylabel="Distance", title=f"{metal} to Elements Distances Violin Plot")

    return interact(metal_distance_violinplot, metal=m_widget); 
开发者ID:sbl-sdsc,项目名称:mmtf-pyspark,代码行数:25,代码来源:structureViewer.py

示例2: interact

# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import interact [as 别名]
def interact(self):

        return ipywidgets.interact(
            self._widget_func,
            weights=self.weights_W,
            weight_clipping=self.weight_clipping_W,
            noise_profile=self.noise_profile_W,
            noise_scale=self.noise_scale_W,
            noise_wave_count=self.noise_wave_count_W,
            noise_base_freq=self.noise_base_freq_W,
            noise_freq_factor=self.noise_freq_factor_W,
            noise_phase_offset_range=self.noise_phase_offset_range_W,
            colour_top=self.colour_top_W,
            colour_bot=self.colour_bot_W,
        ) 
开发者ID:lucashadfield,项目名称:speck,代码行数:17,代码来源:tools.py

示例3: __init__

# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import interact [as 别名]
def __init__(self, loopFunc, **kw):
        self.thread = None
        self.loopFunc = loopFunc
        ipywidgets.interact(self.toggler, x=ipywidgets.ToggleButton(**kw)) 
开发者ID:scanlime,项目名称:fygimbal,代码行数:6,代码来源:fywidgets.py

示例4: crop_recording_window

# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import interact [as 别名]
def crop_recording_window(self):
        self._sample.mspec.spec_stop()
        self._sample.mspec.set_averages(1e4)
        self._sample.mspec.set_window(0,512)
        self._sample.mspec.set_segments(1)
        msp = self._sample.mspec.acquire()
        
        def pltfunc(start,end,done):
            if done:
                self._sample.acqu_window = [start,end]
                self._sample.mspec.set_window(start,end)
                self._sw.disabled = True
                self._ew.disabled = True
                self._dw.disabled = True
                self._dw.description = "acqu_window set to [{:d}:{:d}]".format(start,end)
            else:
                plt.figure(figsize=(15,5))
                plt.plot(msp)
                plt.axvspan(0,start,color='k',alpha=.2)
                plt.axvspan(end,len(msp),color='k',alpha=.2)
                plt.xlim(0,len(msp))
                plt.show()
        self._sw =  widgets.IntSlider(min=0,max=len(msp),step=1,value=self._sample.acqu_window[0],continuous_update=True)
        self._ew = widgets.IntSlider(min=0,max=len(msp),step=1,value=self._sample.acqu_window[1],continuous_update=True)
        self._dw = widgets.Checkbox(value=False,description="Done!",indent=True)
        self._wgt = widgets.interact(pltfunc,start=self._sw,end=self._ew,done=self._dw)
        self._sample.mspec.set_window(*self._sample.acqu_window) 
开发者ID:qkitgroup,项目名称:qkit,代码行数:29,代码来源:initialize.py

示例5: view_structure

# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import interact [as 别名]
def view_structure(pdbIds, bioAssembly = False, style='cartoon', color='spectrum'):
    '''A wrapper function that simply displays a list of protein structures using
    ipywidgets and py3Dmol

    Parameters
    ----------
    pdbIds : list
       A list of PDBIDs to display
    bioAssembly : bool
       display bioAssembly
    style : str, optional
       Style of 3D structure (stick line cross sphere cartoon VDW MS)
    color : str, optional
       Color of 3D structure

    '''
    if type(pdbIds) == str:
        pdbIds = [pdbIds]

    def view3d(i=0):
        '''Simple structure viewer that uses py3Dmol to view PDB structure by
        indexing the list of PDBids

        Parameters
        ----------
            i (int): index of the protein if a list of PDBids
        '''
        print(f"PdbID: {pdbIds[i]}, Style: {style}")


        if '.' not in pdbIds[i]:
            viewer = py3Dmol.view(query='pdb:' + pdbIds[i], options={'doAssembly': bioAssembly})
            viewer.setStyle({style: {'color': color}})
            viewer.setStyle({'hetflag': True},{'stick':{'singleBond':False}})

        else:
            pdbid,chainid = pdbIds[i].split('.')
            viewer = py3Dmol.view(query='pdb:' + pdbid, options={'doAssembly': bioAssembly})
            viewer.setStyle({})
            viewer.setStyle({'chain': chainid}, {style: {'color': color}})
            viewer.setStyle({'chain': chainid, 'hetflag': True},{'stick':{'singleBond':False}})
            viewer.zoomTo({'chain': chainid})

        return viewer.show()

    s_widget = IntSlider(min=0, max=len(pdbIds)-1, description='Structure', continuous_update=False)
    return interact(view3d, i=s_widget) 
开发者ID:sbl-sdsc,项目名称:mmtf-pyspark,代码行数:49,代码来源:structureViewer.py

示例6: view_group_interaction

# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import interact [as 别名]
def view_group_interaction(pdbIds, interacting_group='None', style='cartoon', color='spectrum'):
    '''A wrapper function that simply displays a list of protein structures using
    ipywidgets and py3Dmol and highlight specified interacting groups

    Parameters
    ----------
    pdbIds : list
       A list of PDBIDs to display
    interacting_atom : str, optional
       The interacting atom to highlight
    style : str, optional
       Style of 3D structure (stick line cross sphere cartoon VDW MS)
    color : str, optional 
       Color of 3D structure

    '''
    if type(pdbIds) == str:
        pdbIds = [pdbIds]

    def view3d(i=0):
        '''Simple structure viewer that uses py3Dmol to view PDB structure by
        indexing the list of PDBids

        Parameters
        ----------
            i (int): index of the protein if a list of PDBids
        '''

        print(
            f"PdbID: {pdbIds[i]}, Interactions: {interacting_group}, Style: {style}")

        viewer = py3Dmol.view(query='pdb:' + pdbIds[i])
        viewer.setStyle({style: {'color': color}})

        if interacting_group != "None":

            viewer.setStyle({'resn': interacting_group}, {
                            'sphere': {}})

        return viewer.show()

    s_widget = IntSlider(min=0, max=len(pdbIds)-1, description='Structure', continuous_update=False)
    return interact(view3d, i=s_widget) 
开发者ID:sbl-sdsc,项目名称:mmtf-pyspark,代码行数:45,代码来源:structureViewer.py

示例7: component_viewer

# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import interact [as 别名]
def component_viewer(output, tr=2.0):
    ''' This a function to interactively view the results of a decomposition analysis

    Args:
        output: (dict) output dictionary from running Brain_data.decompose()
        tr: (float) repetition time of data
    '''

    if ipywidgets is None:
        raise ImportError(
            "ipywidgets is required for interactive plotting. Please install this package manually or install nltools with optional arguments: pip install 'nltools[interactive_plots]'"
        )

    def component_inspector(component, threshold):
        '''This a function to be used with ipywidgets to interactively view a decomposition analysis

            Make sure you have tr and output assigned to variables.

            Example:

                from ipywidgets import BoundedFloatText, BoundedIntText
                from ipywidgets import interact

                tr = 2.4
                output = data_filtered_smoothed.decompose(algorithm='ica', n_components=30, axis='images', whiten=True)

                interact(component_inspector, component=BoundedIntText(description='Component', value=0, min=0, max=len(output['components'])-1),
                      threshold=BoundedFloatText(description='Threshold', value=2.0, min=0, max=4, step=.1))

        '''
        _, ax = plt.subplots(nrows=3, figsize=(12,8))
        thresholded = (output['components'][component] - output['components'][component].mean())*(1/output['components'][component].std())
        thresholded.data[np.abs(thresholded.data) <= threshold] = 0
        plot_stat_map(thresholded.to_nifti(), cut_coords=range(-40, 70, 10),
                      display_mode='z', black_bg=True, colorbar=True, annotate=False,
                      draw_cross=False, axes=ax[0])
        if isinstance(output['decomposition_object'], (sklearn.decomposition.PCA)):
            var_exp = output['decomposition_object'].explained_variance_ratio_[component]
            ax[0].set_title(f"Component: {component}/{len(output['components'])}, Variance Explained: {var_exp:2.2}", fontsize=18)
        else:
            ax[0].set_title(f"Component: {component}/{len(output['components'])}", fontsize=18)

        ax[1].plot(output['weights'][:, component], linewidth=2, color='red')
        ax[1].set_ylabel('Intensity (AU)', fontsize=18)
        ax[1].set_title(f'Timecourse (TR={tr})', fontsize=16)
        y = fft(output['weights'][:, component])
        f = fftfreq(len(y), d=tr)
        ax[2].plot(f[f > 0], np.abs(y)[f > 0]**2)
        ax[2].set_ylabel('Power', fontsize=18)
        ax[2].set_xlabel('Frequency (Hz)', fontsize=16)

    ipywidgets.interact(component_inspector, component=ipywidgets.BoundedIntText(description='Component', value=0, min=0, max=len(output['components'])-1),
              threshold=ipywidgets.BoundedFloatText(description='Threshold', value=2.0, min=0, max=4, step=.1)) 
开发者ID:cosanlab,项目名称:nltools,代码行数:55,代码来源:plotting.py


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