<i id='IPdys'><tr id='IPdys'><dt id='IPdys'><q id='IPdys'><span id='IPdys'><b id='IPdys'><form id='IPdys'><ins id='IPdys'></ins><ul id='IPdys'></ul><sub id='IPdys'></sub></form><legend id='IPdys'></legend><bdo id='IPdys'><pre id='IPdys'><center id='IPdys'></center></pre></bdo></b><th id='IPdys'></th></span></q></dt></tr></i><div id='IPdys'><tfoot id='IPdys'></tfoot><dl id='IPdys'><fieldset id='IPdys'></fieldset></dl></div>
    <legend id='IPdys'><style id='IPdys'><dir id='IPdys'><q id='IPdys'></q></dir></style></legend>

      <tfoot id='IPdys'></tfoot>

        <bdo id='IPdys'></bdo><ul id='IPdys'></ul>
    1. <small id='IPdys'></small><noframes id='IPdys'>

      IPython notebook交互功能:如何设置滑块范围

      IPython notebook interactive function: how to set the slider range(IPython notebook交互功能:如何设置滑块范围)

      <legend id='Z8IR2'><style id='Z8IR2'><dir id='Z8IR2'><q id='Z8IR2'></q></dir></style></legend>

    2. <tfoot id='Z8IR2'></tfoot>

      <small id='Z8IR2'></small><noframes id='Z8IR2'>

        <i id='Z8IR2'><tr id='Z8IR2'><dt id='Z8IR2'><q id='Z8IR2'><span id='Z8IR2'><b id='Z8IR2'><form id='Z8IR2'><ins id='Z8IR2'></ins><ul id='Z8IR2'></ul><sub id='Z8IR2'></sub></form><legend id='Z8IR2'></legend><bdo id='Z8IR2'><pre id='Z8IR2'><center id='Z8IR2'></center></pre></bdo></b><th id='Z8IR2'></th></span></q></dt></tr></i><div id='Z8IR2'><tfoot id='Z8IR2'></tfoot><dl id='Z8IR2'><fieldset id='Z8IR2'></fieldset></dl></div>

            <tbody id='Z8IR2'></tbody>
              <bdo id='Z8IR2'></bdo><ul id='Z8IR2'></ul>
                本文介绍了IPython notebook交互功能:如何设置滑块范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在 Ipython notebook 中编写了以下代码来生成一个 sigmoid 函数,该函数由参数 a 控制,该参数定义 sigmoid 中心的位置,b 定义其宽度:

                I wrote the code below in Ipython notebook to generate a sigmoid function controlled by parameters a which defines the position of the sigmoid center, and b which defines its width:

                %matplotlib inline
                    import numpy as np
                    import matplotlib.pyplot as plt
                
                def sigmoid(x,a,b):
                    #sigmoid function with parameters a = center; b = width
                    s= 1/(1+np.exp(-(x-a)/b))
                    return 100.0*(s-min(s))/(max(s)-min(s)) # normalize sigmoid to 0-100
                
                x = np.linspace(0,10,256)
                sigm = sigmoid(x, a=5, b=1)
                fig = plt.figure(figsize=(24,6))
                ax1 = fig.add_subplot(2, 1, 1)
                ax1.set_xticks([])
                ax1.set_xticks([])
                plt.plot(x,sigm,lw=2,color='black')
                plt.xlim(x.min(), x.max())
                

                我想为参数 a 和 b 添加交互性,所以我重写了如下函数:

                I wanted to add interactivity for parameters a and b so I re-wrote the function as below:

                %matplotlib inline
                import numpy as np
                import matplotlib.pyplot as plt
                from IPython.html.widgets import interactive
                from IPython.display import display
                
                def sigmoid_demo(a=5,b=1):
                    x = np.linspace(0,10,256)
                    s = 1/(1+np.exp(-(x-a)/(b+0.1))) # +0.1 to avoid dividing by 0
                    sn = 100.0*(s-min(s))/(max(s)-min(s)) # normalize sigmoid to 0-100
                    fig = plt.figure(figsize=(24,6))
                    ax1 = fig.add_subplot(2, 1, 1)
                    ax1.set_xticks([])
                    ax1.set_yticks([])
                    plt.plot(x,sn,lw=2,color='black')
                    plt.xlim(x.min(), x.max())
                
                w=widgets.interactive(sigmoid_demo,a=5,b=1)
                display(w)
                

                有没有办法将滑块的范围设置为对称(例如大约为零)?在我看来,仅通过设置参数的起始值是不可能的.

                Is there any way to se the range of the sliders to be symmetrical (for example around zero)? It does not seem to me to be possible by just setting the starting value for the parameters.

                推荐答案

                您可以手动创建小部件并将它们绑定到 interactive 函数中的变量.这样您就更加灵活,并且可以根据您的需要定制这些小部件.

                You can create widgets manually and bind them to variables in the interactive function. This way you are much more flexible and can tailor those widgets to your needs.

                本示例创建两个不同的滑块并设置它们的最大值、最小值、步长和初始值,并在 interactive 函数中使用它们.

                This example creates two different sliders and sets their max, min, stepsize and initial value and uses them in the interactive function.

                a_slider = widgets.IntSliderWidget(min=-5, max=5, step=1, value=0)
                b_slider = widgets.FloatSliderWidget(min=-5, max=5, step=0.3, value=0)
                w=widgets.interactive(sigmoid_demo,a=a_slider,b=b_slider)
                display(w)
                

                这篇关于IPython notebook交互功能:如何设置滑块范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                How to extend Python class init(如何扩展 Python 类初始化)
                What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                Initialize list with same bool value(使用相同的布尔值初始化列表)
                setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                  <tfoot id='ao4pi'></tfoot>
                    <bdo id='ao4pi'></bdo><ul id='ao4pi'></ul>

                    1. <legend id='ao4pi'><style id='ao4pi'><dir id='ao4pi'><q id='ao4pi'></q></dir></style></legend>

                        <tbody id='ao4pi'></tbody>
                      <i id='ao4pi'><tr id='ao4pi'><dt id='ao4pi'><q id='ao4pi'><span id='ao4pi'><b id='ao4pi'><form id='ao4pi'><ins id='ao4pi'></ins><ul id='ao4pi'></ul><sub id='ao4pi'></sub></form><legend id='ao4pi'></legend><bdo id='ao4pi'><pre id='ao4pi'><center id='ao4pi'></center></pre></bdo></b><th id='ao4pi'></th></span></q></dt></tr></i><div id='ao4pi'><tfoot id='ao4pi'></tfoot><dl id='ao4pi'><fieldset id='ao4pi'></fieldset></dl></div>

                        • <small id='ao4pi'></small><noframes id='ao4pi'>