小编cal*_*ail的帖子

Matplotlib 根据另一个滑块的变化更新一个滑块

我使用 matplotlib 生成一个带有 2 个滑块的简单绘图,这两个滑块控制绘图上的移动点 - 向用户显示 x 或 y 的变化如何影响该点的位置。我需要这些滑块来彼此共享信息 - 如果一个滑块发生更改,另一个滑块会根据更改的值更新其值(例如,如果控制 x 的滑块发生更改,则控制 y 的滑块也会更新,反之亦然)。

我在 stackoverflow 上对此进行了研究,并尝试实现两种解决方案(第一次尝试在下面的代码中被注释掉),但没有成功。我的尝试的最后一次迭代似乎有效,但过了一会儿它就冻结了情节。

我的代码是:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons

fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)
# Define x values and y function, y = f(2x**2)
x = np.arange(0.0, 11., 1.)
y = x**2
fxplot, = plt.plot(x, y, lw=2)

#define the bullet point to slide on the function
x0=2.
y0=x0**2
x0_old = x0
y0_old = …
Run Code Online (Sandbox Code Playgroud)

python slider matplotlib

2
推荐指数
1
解决办法
2465
查看次数

标签 统计

matplotlib ×1

python ×1

slider ×1