gpt4 book ai didi

python - ipywidgets StaticInteract 绘制所有图像组合

转载 作者:行者123 更新时间:2023-11-28 19:55:12 25 4
gpt4 key购买 nike

我正在使用 iPython notebook 来测试交互功能。几个月前,以下示例(来自 here)对我来说效果很好。但是,如果我现在运行它,它会根据可能的组合绘制所有图像。我不确定这是否重复,但是 this没有帮助。

%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

# mpl.rcParams['figure.max_open_warning'] = 1

def plot(amplitude, color):

fig, ax = plt.subplots(figsize=(4, 3),
subplot_kw={'axisbg':'#EEEEEE',
'axisbelow':True})

ax.grid(color='w', linewidth=2, linestyle='solid')
x = np.linspace(0, 10, 1000)
ax.plot(x, amplitude * np.sin(x), color=color,
lw=5, alpha=0.4)
ax.set_xlim(0, 10)
ax.set_ylim(-1.1, 1.1)

return fig

from ipywidgets import StaticInteract, RangeWidget, RadioWidget

StaticInteract(plot,
amplitude=RangeWidget(0.1, 1.0, 0.1),
color=RadioWidget(['blue', 'green', 'red']))

这是输出: output你能帮帮我吗?

最佳答案

这就是您可以采用的方法。

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from ipywidgets import interact, FloatSlider, RadioButtons

amplitude_slider = FloatSlider(min=0.1, max=1.0, step=0.1, value=0.2)
color_buttons = RadioButtons(options=['blue', 'green', 'red'])
# decorate the plot function with an environment from the UIs:
@interact(amplitude=amplitude_slider, color=color_buttons)
def plot(amplitude, color):
fig, ax = plt.subplots(figsize=(4, 3),
subplot_kw={'axisbg':'#EEEEEE',
'axisbelow':True})

ax.grid(color='w', linewidth=2, linestyle='solid')
x = np.linspace(0, 10, 1000)
ax.plot(x, amplitude * np.sin(x), color=color,
lw=5, alpha=0.4)
ax.set_xlim(0, 10)
ax.set_ylim(-1.1, 1.1)

关于python - ipywidgets StaticInteract 绘制所有图像组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29297858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com