源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Python画图学习入门教程

  • 时间:2021-03-10 02:43 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Python画图学习入门教程
本文实例讲述了Python画图的基本方法。分享给大家供大家参考,具体如下: Python:使用matplotlib绘制图表 python绘制图表的方法,有个强大的类库matplotlib,可以制作出高质量的2D和3D图形,先记录一下,以后慢慢学习。 matplotlib下载及API手册地址:[url=http://sourceforge.net/projects/matplotlib/files/matplotlib/]http://sourceforge.net/projects/matplotlib/files/matplotlib/[/url] 数学库numpy下载及API手册地址:[url=http://www.scipy.org/Download]http://www.scipy.org/Download[/url] 几个绘图的例子,来自API手册: [b]1、最简单的图:[/b] 代码:
#!/usr/bin/env python
import matplotlib.pyplot as plt
plt.plot([10, 20, 30])
plt.xlabel('tiems')
plt.ylabel('numbers')
plt.show()

[b]2.饼图:[/b] 代码:
#!/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()

[b]3、使用numpy库函数:[/b] 代码:
#!/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相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/788.htm]Python编码操作技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/645.htm]Python图片操作技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/663.htm]Python数据结构与算法教程[/url]》、《[url=http://www.1sucai.cn/Special/648.htm]Python Socket编程技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/642.htm]Python函数使用技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/636.htm]Python字符串操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/520.htm]Python入门与进阶经典教程[/url]》及《[url=http://www.1sucai.cn/Special/516.htm]Python文件与目录操作技巧汇总[/url]》 希望本文所述对大家Python程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部