在matplotlib小部件中单击按钮时提取/打印滑块值(Python 2.7)

亚伦·金

我正在使用Matplotlib滑块小部件的模板。我正在使用模板。如何更改“重置”按钮下的脚本以打印出Amp和Freq滑块的值?

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

ax = plt.subplot(111)
plt.subplots_adjust(left=0.25, bottom=0.25)
t = np.arange(0.0, 1.0, 0.001)
a0 = 5
f0 = 3
s = a0*np.sin(2*np.pi*f0*t)
l, = plt.plot(t,s, lw=2, color='red')
plt.axis([0, 1, -10, 10])

axcolor = 'lightgoldenrodyellow'
axfreq = plt.axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor)
axamp  = plt.axes([0.25, 0.15, 0.65, 0.03], axisbg=axcolor)

sfreq = Slider(axfreq, 'Freq', 0.1, 30.0, valinit=f0)
samp = Slider(axamp, 'Amp', 0.1, 10.0, valinit=a0)

def update(val):
    amp = samp.val
    freq = sfreq.val
    l.set_ydata(amp*np.sin(2*np.pi*freq*t))
    plt.draw()
sfreq.on_changed(update)
samp.on_changed(update)

resetax = plt.axes([0.8, 0.025, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')

def reset(event):
    sfreq.reset()
    samp.reset()
button.on_clicked(reset)

rax = plt.axes([0.025, 0.5, 0.15, 0.15], axisbg=axcolor)
radio = RadioButtons(rax, ('red', 'blue', 'green'), active=0)
def colorfunc(label):
    l.set_color(label)
    plt.draw()
radio.on_clicked(colorfunc)

plt.show()
重要性

在上面的代码中,将reset函数替换为类似

def reset(event):
    print "Amplitude: ",  samp.val
    #sfreq.reset()
    #samp.reset()

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

GTK + 2 C-输入按下或单击按钮以从条目小部件中获取文本

来自分类Dev

GTK + 2 C-输入按下或单击按钮以从条目小部件中获取文本

来自分类Dev

在go lang中,为什么是7?断言(5 ^ 2 == 7)

来自分类Dev

在 Framework 7 v2 中单击按钮重新加载页面

来自分类Dev

在Windows 7中无法删除文件(2)

来自分类Dev

在Angular 2中单击按钮时更新列表项的值

来自分类Dev

尝试在Xcode 7 / Swift 2中播放视频时出错

来自分类Dev

Windows 7中托管的GExiv2.py(Python)

来自分类Dev

按语言在drupal7中的2层滑块之间切换

来自分类Dev

按语言在drupal7中的2层滑块之间切换

来自分类Dev

在relativelayout中关联2小部件时出错

来自分类Dev

奇怪的错误,ValueError:传递的值的形状为(7,4),索引暗示(7,2)

来自分类Dev

Windows 7:系统时钟比每次启动晚2小时

来自分类Dev

C / C ++中的快速7x7 2D中值滤波器

来自分类Dev

Think Python 2nd Edition 练习 7-1

来自分类Dev

在Symfony 2(.7)中禁用不推荐使用的警告

来自分类Dev

MPICH2无法在Windows 7中执行mpiexec

来自分类Dev

如何在XCode 7中添加libxml2.dylib

来自分类Dev

在iOS 7中2秒后随机更改UIImage

来自分类Dev

PHPDocumentor 2和PHP 7在Doctrine中存在opcache问题

来自分类Dev

在MATLAB中通过[-2,7]绘制函数符号

来自分类Dev

在Delphi 7中使用2个目录输出?

来自分类Dev

递归比较CentOS 7中2个目录的内容

来自分类Dev

Xcode 7,Swift 2中的Gmail API iOS

来自分类Dev

SKCropNode在Xcode 7 + Swift 2中无法正常工作

来自分类Dev

什么是Delphi XE7中的“ HotfixLevel 2”?

来自分类Dev

如何在 eclipse neon 2 中运行 java 7 项目?

来自分类Dev

angular7 中 2 个模块的声明错误

来自分类Dev

单击Struts 2中的按钮时弹出

Related 相关文章

  1. 1

    GTK + 2 C-输入按下或单击按钮以从条目小部件中获取文本

  2. 2

    GTK + 2 C-输入按下或单击按钮以从条目小部件中获取文本

  3. 3

    在go lang中,为什么是7?断言(5 ^ 2 == 7)

  4. 4

    在 Framework 7 v2 中单击按钮重新加载页面

  5. 5

    在Windows 7中无法删除文件(2)

  6. 6

    在Angular 2中单击按钮时更新列表项的值

  7. 7

    尝试在Xcode 7 / Swift 2中播放视频时出错

  8. 8

    Windows 7中托管的GExiv2.py(Python)

  9. 9

    按语言在drupal7中的2层滑块之间切换

  10. 10

    按语言在drupal7中的2层滑块之间切换

  11. 11

    在relativelayout中关联2小部件时出错

  12. 12

    奇怪的错误,ValueError:传递的值的形状为(7,4),索引暗示(7,2)

  13. 13

    Windows 7:系统时钟比每次启动晚2小时

  14. 14

    C / C ++中的快速7x7 2D中值滤波器

  15. 15

    Think Python 2nd Edition 练习 7-1

  16. 16

    在Symfony 2(.7)中禁用不推荐使用的警告

  17. 17

    MPICH2无法在Windows 7中执行mpiexec

  18. 18

    如何在XCode 7中添加libxml2.dylib

  19. 19

    在iOS 7中2秒后随机更改UIImage

  20. 20

    PHPDocumentor 2和PHP 7在Doctrine中存在opcache问题

  21. 21

    在MATLAB中通过[-2,7]绘制函数符号

  22. 22

    在Delphi 7中使用2个目录输出?

  23. 23

    递归比较CentOS 7中2个目录的内容

  24. 24

    Xcode 7,Swift 2中的Gmail API iOS

  25. 25

    SKCropNode在Xcode 7 + Swift 2中无法正常工作

  26. 26

    什么是Delphi XE7中的“ HotfixLevel 2”?

  27. 27

    如何在 eclipse neon 2 中运行 java 7 项目?

  28. 28

    angular7 中 2 个模块的声明错误

  29. 29

    单击Struts 2中的按钮时弹出

热门标签

归档