Jupyter-如何对功能进行交互式更新?

发布于 2025-02-09 13:49:00 字数 1382 浏览 3 评论 0原文

def sort_category (category, file_source):
        file = file_source.loc[file_source['Odds Category'] == category]
        return file

def plot_graph (a, b):
    plt.plot(a,b)

def calcul (bankroll_init, bet_init, multiplier, odds_category, file_source):
    
    sorted_file = sort_category(odds_category, file_source)
    bankroll_current = bankroll_init
    bet_current = bet_init
    list_bankroll = []
    list_date = []

    for i in sorted_file.index:
        
        list_bankroll.append(bankroll_current)
        list_date.append(sorted_file['Date'][i])
        bankroll_current = bankroll_current - bet_current
        
        if (sorted_file['B365H'][i] == sorted_file['Min Odds'][i]) & (sorted_file['FTR'][i] == 'H'):
            bankroll_current = bankroll_current + (bet_current * sorted_file['B365H'][i])
            bet_current = bet_init

        elif (sorted_file['B365A'][i] == sorted_file['Min Odds'][i]) & (sorted_file['FTR'][i] == 'A'):
            bankroll_current = bankroll_current + (bet_current * sorted_file['B365A'][i])
            bet_current = bet_init
        else :
            bet_current = bet_current * multiplier
    
    plot_graph(list_date,list_bankroll)
   

calcul(10000,10,2,4,ligue_1)

该代码通过“ plot_graph”函数绘制图形,该函数在'calcul'函数中被称为。

有没有一种方法可以通过滑块或下拉菜单更新我的“计算”功能的五个参数?这些参数是改变图形的条件。

谢谢

def sort_category (category, file_source):
        file = file_source.loc[file_source['Odds Category'] == category]
        return file

def plot_graph (a, b):
    plt.plot(a,b)

def calcul (bankroll_init, bet_init, multiplier, odds_category, file_source):
    
    sorted_file = sort_category(odds_category, file_source)
    bankroll_current = bankroll_init
    bet_current = bet_init
    list_bankroll = []
    list_date = []

    for i in sorted_file.index:
        
        list_bankroll.append(bankroll_current)
        list_date.append(sorted_file['Date'][i])
        bankroll_current = bankroll_current - bet_current
        
        if (sorted_file['B365H'][i] == sorted_file['Min Odds'][i]) & (sorted_file['FTR'][i] == 'H'):
            bankroll_current = bankroll_current + (bet_current * sorted_file['B365H'][i])
            bet_current = bet_init

        elif (sorted_file['B365A'][i] == sorted_file['Min Odds'][i]) & (sorted_file['FTR'][i] == 'A'):
            bankroll_current = bankroll_current + (bet_current * sorted_file['B365A'][i])
            bet_current = bet_init
        else :
            bet_current = bet_current * multiplier
    
    plot_graph(list_date,list_bankroll)
   

calcul(10000,10,2,4,ligue_1)

This code plot a graphic through the "plot_graph" function, which is called in the 'calcul' function.

Is there a way to update the five arguments of my 'calcul' function with sliders or dropdown menus ? These arguments are conditions that change the graphic.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撞了怀 2025-02-16 13:49:00

我留给您以适应您的情况:

ipywidgets库中有很多小部件,您可以发现在这里。在示例中,我只放了很少的内容,因此您可以看到我们如何使用

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

@wg.interact(Slider_1 = wg.IntSlider(min=0, max=10, step=1, value=3, description='Sliter_A'),
             Slider_2 = wg.FloatSlider(min=-2, max=1, step=0.1),
             Check    = wg.Checkbox(False),
             Radio = wg.RadioButtons(options=["string", 3.14], description="xox"),
             DP = wg.Dropdown(options=['X', 'Y', 2, 'Random', 3],value=2, description='options :')
             )
def run(Slider_1, Slider_2, Check, Radio, DP):
    if(Check == True):
        plt.text(0,0.5, "see this?")
    else:
        plt.scatter(0,0, s=50, color='red')
    
    plt.text(0,0.02,Radio)
    
    x = np.linspace(-6,6,1000)
    plt.plot(x, Slider_1*x**2 + Slider_2)
    plt.xlim(-3,3)
    plt.ylim(-3,3)

“在此处输入图像说明”

I leave it to you to adapt this code for your case :

there are lot of widgets in ipywidgets library that you can discover here. In the example I put only few of them so you can see how do we use

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

@wg.interact(Slider_1 = wg.IntSlider(min=0, max=10, step=1, value=3, description='Sliter_A'),
             Slider_2 = wg.FloatSlider(min=-2, max=1, step=0.1),
             Check    = wg.Checkbox(False),
             Radio = wg.RadioButtons(options=["string", 3.14], description="xox"),
             DP = wg.Dropdown(options=['X', 'Y', 2, 'Random', 3],value=2, description='options :')
             )
def run(Slider_1, Slider_2, Check, Radio, DP):
    if(Check == True):
        plt.text(0,0.5, "see this?")
    else:
        plt.scatter(0,0, s=50, color='red')
    
    plt.text(0,0.02,Radio)
    
    x = np.linspace(-6,6,1000)
    plt.plot(x, Slider_1*x**2 + Slider_2)
    plt.xlim(-3,3)
    plt.ylim(-3,3)

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文