亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Jupyter?ipywidgets組件的使用及說明

 更新時(shí)間:2023年06月25日 08:43:25   作者:阿濤的一天  
這篇文章主要介紹了Jupyter?ipywidgets組件的使用及說明,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Jupyter ipywidgets組件使用

ipywidgets

ipywidgets可以用于在jupyter notebook當(dāng)中進(jìn)行界面設(shè)計(jì),以及一些簡單的交互式控件操作。

SelectMultiple(復(fù)選框框組件取值)

from ipywidgets import interact,widgets
from ipywidgets import interact
from ipywidgets import Button, Layout
#樣例列表
test_list = ['first','second','third','forth','fifth','sixth']
productcode = widgets.SelectMultiple(
    options=test_list,			#可選參數(shù)
    value=[test_list[0]],		#默認(rèn)選項(xiàng)
    rows=6,						#顯示行數(shù)
    description='產(chǎn)品代碼:',	#描述信息
    disabled=False				#是否不可用
)
#提交按鈕
submit_buttom = widgets.Button(
    description='提交',
    layout=Layout(width='30%', height='50px'),
    button_style='success'
)
#觸發(fā)函數(shù)
def btn_click(sender):
    print(productcode.value)
#綁定觸發(fā)函數(shù)
submit_buttom.on_click(btn_click)
#組件展示
display(productcode,submit_buttom)

執(zhí)行效果

DatePicker(獲取日期組件的值)

from ipywidgets import interact,widgets
from ipywidgets import interact
from ipywidgets import Button, Layout
current_time = widgets.DatePicker(
    description='生成日期:',
    disabled=False
)
submit_buttom = widgets.Button(
    description='提交',
    layout=Layout(width='30%', height='50px'),
    button_style='success'
)
def btn_click(sender):
    print(current_time.value)
submit_buttom.on_click(btn_click)
display(current_time,submit_buttom)

執(zhí)行效果

DatePicker(獲取日期組件的值)

from ipywidgets import interact,widgets
from ipywidgets import interact
from ipywidgets import Button, Layout
Dropdown_test = widgets.Dropdown(description='餅圖1:',options=[("必選項(xiàng)", 1), ("展示", 2) ,("不展示", 3)], index=0, value=1, label="必選項(xiàng)")
def chosen(_):
    print("Selected index:{}, value:{}, label:{}".format(pie_first.index, pie_first.value, pie_first.label))
pie_first.observe(chosen, names="value")
submit_buttom = widgets.Button(
    description='提交',
    layout=Layout(width='30%', height='50px'),
    button_style='success'
)
def btn_click(sender):
    print(Dropdown_test.label)
submit_buttom.on_click(btn_click)
display(Dropdown_test,submit_buttom)

交互控件ipywidgets在jupyter notebook中的使用

ipywidgets是已集成到anaconda中的一款非常簡單好用的交互控件。

本文以三個(gè)常用的例子展示ipywidgets的使用,更為詳細(xì)的用法可參考官網(wǎng)ipywidgets

import numpy as np
import matplotlib.pyplot as plt
import ipywidgets as widgets

簡單交互圖

def func(a, b, color, title, text):
    x = np.linspace(0,10,10)
    plt.plot(a*x+b, c=color)
    if title:
        plt.title(text)
widgets.interactive(func, a=[1,2,3], b=(100,200,0.5), color=["r", "b"], title=True, text="interactive fig")

利用播放器繪制動(dòng)態(tài)圖

play = widgets.Play(
    value=50,
    min=0,
    max=100,
    step=1,
    description="Press play",
    disabled=False
)
def func(b):
    x = np.linspace(0,10,100)
    plt.plot(np.sin(x+b/10.0))
    plt.title(f"b is ")
    plt.show()
widgets.interactive(func, b=play)

為播放器添加進(jìn)度條

play = widgets.Play(
    value=50,
    min=0,
    max=100,
    step=1,
    description="Press play",
    disabled=False
)
# slider = widgets.IntSlider()
slider = widgets.IntProgress()
widgets.jslink((play, 'value'), (slider, 'value'))
ui = widgets.HBox([play, slider])
out = widgets.interactive_output(func, {"b":play})
display(ui, out)

Output()

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 利用python實(shí)現(xiàn)簡單的情感分析實(shí)例教程

    利用python實(shí)現(xiàn)簡單的情感分析實(shí)例教程

    商品評論挖掘、電影推薦、股市預(yù)測……情感分析大有用武之地,下面這篇文章主要給大家介紹了關(guān)于利用python實(shí)現(xiàn)簡單的情感分析的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-06-06
  • 如何在Python中妥善使用進(jìn)度條詳解

    如何在Python中妥善使用進(jìn)度條詳解

    python的進(jìn)度條有很多第三方庫,有些做的比較炫酷,下面這篇文章主要給大家介紹了關(guān)于如何在Python中妥善使用進(jìn)度條的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-04-04
  • 詳解Python中DOM方法的動(dòng)態(tài)性

    詳解Python中DOM方法的動(dòng)態(tài)性

    這篇文章主要介紹了詳解Python中DOM方法的動(dòng)態(tài)性,xml.dom模塊在Python的網(wǎng)絡(luò)編程中相當(dāng)有用,本文來自于IBM官網(wǎng)的開發(fā)者技術(shù)文檔,需要的朋友可以參考下
    2015-04-04
  • 解決python pandas讀取excel中多個(gè)不同sheet表格存在的問題

    解決python pandas讀取excel中多個(gè)不同sheet表格存在的問題

    這篇文章主要介紹了解決python pandas讀取excel中多個(gè)不同sheet表格存在的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • Python之print函數(shù)里逗號(hào)和加號(hào)的區(qū)別及說明

    Python之print函數(shù)里逗號(hào)和加號(hào)的區(qū)別及說明

    這篇文章主要介紹了Python之print函數(shù)里逗號(hào)和加號(hào)的區(qū)別及說明,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • Python中json常見四種用法舉例

    Python中json常見四種用法舉例

    這篇文章主要給大家介紹了關(guān)于Python中json常見四種用法舉例的相關(guān)資料,眾所周知JSON是一種輕量級(jí)的數(shù)據(jù)交換格式,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-08-08
  • 基于Python打造高效便捷的目錄結(jié)構(gòu)生成器

    基于Python打造高效便捷的目錄結(jié)構(gòu)生成器

    這篇文章主要為大家詳細(xì)介紹了如何使用Python開發(fā)一個(gè)目錄結(jié)構(gòu)生成器,它不僅能夠幫助用戶高效地生成文件夾目錄結(jié)構(gòu),還具備了很多智能化的功能,感興趣的小伙伴可以了解下
    2025-04-04
  • 聊聊基于pytorch實(shí)現(xiàn)Resnet對本地?cái)?shù)據(jù)集的訓(xùn)練問題

    聊聊基于pytorch實(shí)現(xiàn)Resnet對本地?cái)?shù)據(jù)集的訓(xùn)練問題

    本文項(xiàng)目是使用Resnet模型來識(shí)別螞蟻和蜜蜂,其一共有三百九十六張的數(shù)據(jù),訓(xùn)練集只有兩百多張(數(shù)據(jù)集很?。?,運(yùn)行十輪后,分別對訓(xùn)練集和測試集在每一輪的準(zhǔn)確率,對pytorch實(shí)現(xiàn)Resnet本地?cái)?shù)據(jù)集的訓(xùn)練感興趣的朋友一起看看吧
    2022-03-03
  • python 爬取壁紙網(wǎng)站的示例

    python 爬取壁紙網(wǎng)站的示例

    這篇文章主要介紹了python 爬取壁紙網(wǎng)站的示例,幫助大家更好的理解和學(xué)習(xí)使用python爬蟲,感興趣的朋友可以了解下
    2021-03-03
  • 使用Django實(shí)現(xiàn)把兩個(gè)模型類的數(shù)據(jù)聚合在一起

    使用Django實(shí)現(xiàn)把兩個(gè)模型類的數(shù)據(jù)聚合在一起

    這篇文章主要介紹了使用Django實(shí)現(xiàn)把兩個(gè)模型類的數(shù)據(jù)聚合在一起,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03

最新評論