Python ipywidgets.interact() Examples
The following are 10
code examples of ipywidgets.interact().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ipywidgets
, or try the search function
.
Example #1
Source File: structureViewer.py From mmtf-pyspark with Apache License 2.0 | 6 votes |
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);
Example #2
Source File: tools.py From speck with GNU General Public License v3.0 | 5 votes |
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, )
Example #3
Source File: fywidgets.py From fygimbal with MIT License | 5 votes |
def __init__(self, loopFunc, **kw): self.thread = None self.loopFunc = loopFunc ipywidgets.interact(self.toggler, x=ipywidgets.ToggleButton(**kw))
Example #4
Source File: fywidgets.py From fygimbal with MIT License | 5 votes |
def __init__(self, gimbal): self.gimbal = gimbal ipywidgets.interact(self.fn, x=ipywidgets.ToggleButton(description='Motor Enable'))
Example #5
Source File: fywidgets.py From fygimbal with MIT License | 5 votes |
def __init__(self, gimbal, number, axes=range(3), min=-0x8000, max=0x7fff, step=1): self.gimbal = gimbal self.number = number self.axes = axes self.widgets = [None] * 3 ThreadToggle(self._update, description='Refresh param %02x' % number) for t in self.axes: v = self.gimbal.getParam(number=number, target=t) self.widgets[t] = ipywidgets.IntSlider(description='Param %02x t=%d' % (self.number, t), value=v, min=min, max=max, step=step,layout=dict(width='100%')) ipywidgets.interact(self._set, x=self.widgets[t], target=ipywidgets.fixed(t))
Example #6
Source File: fywidgets.py From fygimbal with MIT License | 5 votes |
def __init__(self, gimbal): self.gimbal = gimbal self.controlPacket = None xw = ipywidgets.IntSlider(value=0, min=-0x8000, max=0x7fff, step=1, layout=dict(width='100%')) yw = ipywidgets.IntSlider(value=0, min=-0x8000, max=0x7fff, step=1, layout=dict(width='100%')) zw = ipywidgets.IntSlider(value=0, min=-0x8000, max=0x7fff, step=1, layout=dict(width='100%')) mw = ipywidgets.IntSlider(value=1, min=0, max=255, step=1, layout=dict(width='100%')) ipywidgets.interact(self.setFn, x=xw, y=yw, z=zw, m=mw) ThreadToggle(self.loopFn, description='Controller thread') self.rate = ipywidgets.IntSlider(description='Update rate', value=25, min=1, max=400, step=1, layout=dict(width='100%')) display(self.rate)
Example #7
Source File: initialize.py From qkit with GNU General Public License v2.0 | 5 votes |
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)
Example #8
Source File: structureViewer.py From mmtf-pyspark with Apache License 2.0 | 4 votes |
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)
Example #9
Source File: structureViewer.py From mmtf-pyspark with Apache License 2.0 | 4 votes |
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)
Example #10
Source File: plotting.py From nltools with MIT License | 4 votes |
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))