Python--绘图工具matplotlib的使用
来源:互联网 发布:航海家炒股软件 公式 编辑:程序博客网 时间:2024/06/07 10:02
1、下载并安装适合自己Python的numpy安装包
numpy : http://sourceforge.net/projects/numpy/files/NumPy/1.7.1/
2、下载并安装matplotlib
matplotlib : http://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib
3、点击按钮实现画一个正弦波
from Tkinter import *import matplotlib.pyplot as pltimport numpy as npdef draw_sin():#draw a circle of sint = np.arange(1,256,1)y = np.sin(2*np.pi*t/256)plt.plot(t,y,'g')plt.show()root = Tk(className = 'DrawSin')label = Label(root)label['text'] = 'Draw Sin'label.pack()button = Button(root)button['text'] = 'Draw'button['command'] = draw_sinbutton.pack()root.mainloop()
效果
显示主菜单
点击按钮实现画图
4、点击按钮实现波形的变化
#!usr/bin/env/python#coding=utf-8from Tkinter import *import matplotlib.pyplot as pltimport numpy as npimport sys#number of pointNumber = 1024#init frequency valuefrequency = 1#set the recur depthsys.setrecursionlimit(1000000)def draw_sin():'''raw a circle of sin'''#generate the time baset = np.arange(1,Number,1)#generate the signaly = np.sin(2*np.pi*frequency*t/Number)plt.plot(t,y)plt.grid(True)plt.text(900,0.75,'Frequency is '+str(frequency))plt.show()def frequency_plus():'''function of add the frequency and plot the signal'''#notice:frequency is a global variableglobal frequency frequency = frequency + 1#clear a figure windowplt.clf()draw_sin()def my_button(root,label_text,button_text,button_func):'''function of creat label and button'''#label detailslabel = Label(root)label['text'] = label_textlabel.pack()#label detailsbutton = Button(root)button['text'] = button_textbutton['command'] = button_funcbutton.pack()def main():'''main function'''root = Tk(className = 'DrawSin')#draw button functionmy_button(root,'Draw sin','click to Draw',draw_sin)#frequency plus functionmy_button(root,'Freq Plus','click to Plus',frequency_plus)root.mainloop()if __name__ == "__main__":main()
效果
显示主菜单
点击按钮实现频率改变
5、可能出现的问题
RuntimeError: maximum recursion depth exceeded
解决方法:
http://blog.csdn.net/lmh12506/article/details/7865288
网上学习资料:
matplotlib手册
http://wenku.baidu.com/view/dcee911cfad6195f312ba61c.htmlpython使用matplotlib绘图
http://www.cnblogs.com/qianlifeng/archive/2012/02/13/2350086.html
- Python--绘图工具matplotlib的使用
- Python绘图工具matplotlib的安装
- matplotlib绘图工具使用
- python使用matplotlib绘图
- Python:使用Matplotlib绘图
- python使用matplotlib绘图
- python使用matplotlib绘图 -- barChart
- python使用matplotlib绘图 -- barChart
- 使用 python Matplotlib 库绘图
- 使用 python Matplotlib 库绘图
- python使用matplotlib绘图 -- barChart
- 使用 python Matplotlib 库绘图
- 使用 python Matplotlib 库绘图
- 使用 python Matplotlib 库绘图
- python使用matplotlib绘图 -- barChart
- 使用 python Matplotlib 库绘图
- 使用 python Matplotlib 库绘图
- python使用matplotlib绘图 -- barChart
- Sicily 1543 Completing Brackets (SOJ 1543) 【括号匹配】
- [Python]项目打包:5步将py文件打包成exe文件
- C++读书笔记之 赋值运算符= 重载 前缀自减运算符--重载 求负运算符- 重载
- 淘宝网店优惠券营销活动攻略
- a famous quote by Calvin Coolidge (1872) Persistence and determination alone are omnipotent
- Python--绘图工具matplotlib的使用
- libvirt API 简介(二)
- 历史名人1——美尼斯
- Java编程思想--一切皆是对象
- axis2使用教程、webservices自定义参数,webservices自定义返回值
- Mule Studio版本3.4案例--Foreach Processing and Choice Routing Example
- NotePad++格式化sql文本插件
- Git详解之六 Git工具
- LinkButton控件