Python:使用matplotlib绘制图表
2015-05-04 15:21
1351 查看
今天看了一下使用python绘制图表的方法,有个强大的类库matplotlib,可以制作出高质量的2D和3D图形,先记录一下,以后慢慢学习。
matplotlib下载及API手册地址:http://sourceforge.net/projects/matplotlib/files/matplotlib/
数学库numpy下载及API手册地址:http://www.scipy.org/Download
几个绘图的例子,来自API手册:
1、最简单的图:
代码:
[python] view
plaincopyprint?
#!/usr/bin/env python
import matplotlib.pyplot as plt
plt.plot([10, 20, 30])
plt.xlabel('tiems')
plt.ylabel('numbers')
plt.show()
测试:
2.饼图:
代码:
[python] view
plaincopyprint?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pylab import *
# make a square figure and axes
figure(1, figsize=(6,6))
ax = axes([0.1, 0.1, 0.8, 0.8])
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15,30,45, 10]
explode=(0, 0.05, 0, 0)
pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)
title('Raining Hogs and Dogs', bbox={'facecolor':'0.8', 'pad':5})
savefig('D:\\pie.png')
show()
测试:
3、使用numpy库函数:
代码:
[python] view
plaincopyprint?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
t = np.arange(0.0, 1.01, 0.01)
s = np.sin(2*2*np.pi*t)
plt.fill(t, s*np.exp(-5*t), 'r')
plt.grid(True)
#保存为PDF格式,也可保存为PNG等图形格式
plt.savefig('D:\\test.pdf')
plt.show()
测试:
matplotlib下载及API手册地址:http://sourceforge.net/projects/matplotlib/files/matplotlib/
数学库numpy下载及API手册地址:http://www.scipy.org/Download
几个绘图的例子,来自API手册:
1、最简单的图:
代码:
[python] view
plaincopyprint?
#!/usr/bin/env python
import matplotlib.pyplot as plt
plt.plot([10, 20, 30])
plt.xlabel('tiems')
plt.ylabel('numbers')
plt.show()
测试:
2.饼图:
代码:
[python] view
plaincopyprint?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pylab import *
# make a square figure and axes
figure(1, figsize=(6,6))
ax = axes([0.1, 0.1, 0.8, 0.8])
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15,30,45, 10]
explode=(0, 0.05, 0, 0)
pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)
title('Raining Hogs and Dogs', bbox={'facecolor':'0.8', 'pad':5})
savefig('D:\\pie.png')
show()
测试:
3、使用numpy库函数:
代码:
[python] view
plaincopyprint?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
t = np.arange(0.0, 1.01, 0.01)
s = np.sin(2*2*np.pi*t)
plt.fill(t, s*np.exp(-5*t), 'r')
plt.grid(True)
#保存为PDF格式,也可保存为PNG等图形格式
plt.savefig('D:\\test.pdf')
plt.show()
测试:
相关文章推荐
- Python:使用matplotlib绘制图表
- Python:使用matplotlib绘制图表
- python 使用numpy matplotlib绘制图表
- Python:使用matplotlib绘制图表
- python: 使用matplotlib的pyplot绘制图表
- 使用python matplotlib绘制高级图表
- Python:使用matplotlib绘制图表
- 《机器学习实战》——在python中使用Matplotlib注解绘制树形图
- python使用matplotlib绘制折线图教程
- Python图表绘制:matplotlib绘图库入门
- Python图表绘制:matplotlib绘图库入门
- Python图表绘制:matplotlib绘图库入门
- Python图表绘制:matplotlib绘图库入门
- Python图表绘制:matplotlib绘图库入门
- Python图表绘制:matplotlib绘图库入门
- Python图表绘制:matplotlib绘图库入门
- Python使用matplotlib绘制动画的方法
- Python使用matplotlib绘制动画的方法
- 在Linux下使用Python的matplotlib绘制数据图的教程
- 在Linux下使用Python的matplotlib绘制数据图的教程