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

        <bdo id='cWNxz'></bdo><ul id='cWNxz'></ul>

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

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

        Matplotlib 依赖的滑块

        时间:2023-10-19
        <i id='CRwEQ'><tr id='CRwEQ'><dt id='CRwEQ'><q id='CRwEQ'><span id='CRwEQ'><b id='CRwEQ'><form id='CRwEQ'><ins id='CRwEQ'></ins><ul id='CRwEQ'></ul><sub id='CRwEQ'></sub></form><legend id='CRwEQ'></legend><bdo id='CRwEQ'><pre id='CRwEQ'><center id='CRwEQ'></center></pre></bdo></b><th id='CRwEQ'></th></span></q></dt></tr></i><div id='CRwEQ'><tfoot id='CRwEQ'></tfoot><dl id='CRwEQ'><fieldset id='CRwEQ'></fieldset></dl></div>
      2. <small id='CRwEQ'></small><noframes id='CRwEQ'>

      3. <legend id='CRwEQ'><style id='CRwEQ'><dir id='CRwEQ'><q id='CRwEQ'></q></dir></style></legend>
          <tbody id='CRwEQ'></tbody>
        <tfoot id='CRwEQ'></tfoot>

              <bdo id='CRwEQ'></bdo><ul id='CRwEQ'></ul>

                  本文介绍了Matplotlib 依赖的滑块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想通过选择权重来选择三角形的一个点.这应该通过控制 2 个滑块 (matplotlib.widgets.Slider) 来完成.这两个滑块表示定义点的三个权重中的两个.第三个权重很容易计算为1.0 -slider1 -slider2.

                  I want to choose a point of a triangle by choosing its weights. This should be done by controlling 2 Sliders (matplotlib.widgets.Slider). These two sliders express two out of three weights that define the point. The third weight is easily calculated as 1.0 - slider1 - slider2.

                  现在很明显,所有权重的总和应该等于 1.0,因此选择 0.8 和 0.9 作为两个滑块的值应该是不可能的.参数 slidermax 允许使滑块依赖,但我不能说:

                  Now it is clear that the sum of all weights should be equal to 1.0, so choosing 0.8 and 0.9 as the values for the two sliders should be impossible. The argument slidermax allows to make sliders dependent, but I can not say:

                  slider2 = Slider(... , slidermax = 1.0-slider1)
                  

                  slidermax 需要类型 Slider,而不是 integer.如何创建比此 slidermax 选项更复杂的依赖项?

                  slidermax requires a type Slider, not integer. How can I create dependencies a little more complex than this slidermax option?

                  推荐答案

                  @ubuntu 的回答很简单.

                  @ubuntu's answer is the simple way.

                  另一种选择是继承 Slider 来做你想做的事.这将是最灵活的(您甚至可以让滑块相互更新,目前它们还没有这样做).

                  Another option is to subclass Slider to do exactly what you want. This would be the most flexible (and you could even make the sliders update each other, which they currently don't do).

                  但是,在这种情况下使用ducktyping"很容易.唯一的要求是 sliderminslidermax 有一个 val 属性.它们实际上不必是 Slider 的实例.

                  However, it's easy to use "ducktyping" in this case. The only requirement is that slidermin and slidermax have a val attribute. They don't actually have to be instances of Slider.

                  考虑到这一点,您可以执行以下操作:

                  With that in mind, you could do something like:

                  import matplotlib.pyplot as plt
                  from matplotlib.widgets import Slider
                  
                  class FakeSlider(object):
                      def __init__(self, slider, func):
                          self.func, self.slider = func, slider
                      @property
                      def val(self):
                          return self.func(self.slider.val)
                  
                  fig, ax = plt.subplots()
                  fig.subplots_adjust(bottom=0.25)
                  
                  sliderax1 = fig.add_axes([0.15, 0.1, 0.75, 0.03], axisbg='gray')
                  sliderax2  = fig.add_axes([0.15, 0.15, 0.75, 0.03], axisbg='gray')
                  
                  slider1 = Slider(sliderax1, 'Value 1', 0.1, 5, valinit=2)
                  slider2 = Slider(sliderax2, 'Value 2', -4, 0.9, valinit=-3,
                                   slidermax=FakeSlider(slider1, lambda x: 1 - x))
                  plt.show()
                  

                  这篇关于Matplotlib 依赖的滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:同时使用 Matplotlib Slider 和 key_release_event 下一篇:逐行比较文件是否相同,如果相同则输出它们

                  相关文章

                    <bdo id='sTqVq'></bdo><ul id='sTqVq'></ul>

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

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

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