用matplotlib作图步骤
2016-01-18 22:12
666 查看
装完matplotlib完后立即着手实践。找了一段代码来完成作业图
环境: windows
Python版本: 2.7
Python开发工具:IDLE
(1)打开shell终端窗口,选择File菜单下的New File 选项,新建一个python文件,命名1.py,并保存
(2)此时shell终端就会变成编辑界面,会多出Run菜单,选择运行即可,出现图形好激动,有没有哈。。。
(3)附:我的源码如下:
import numpy as np
import matplotlib.pyplot as plt
N = 5
menMeans = (20, 35, 30, 35, 27)
menStd = (2, 3, 4, 1, 2)
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)
womenMeans = (25, 32, 34, 20, 25)
womenStd = (3, 5, 2, 3, 3)
rects2 = ax.bar(ind+width, womenMeans, width, color='y', yerr=womenStd)
# add some
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind+width)
ax.set_xticklabels( ('G1', 'G2', 'G3', 'G4', 'G5') )
ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') )
def autolabel(rects):
# attach some text labels
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
plt.show()
环境: windows
Python版本: 2.7
Python开发工具:IDLE
(1)打开shell终端窗口,选择File菜单下的New File 选项,新建一个python文件,命名1.py,并保存
(2)此时shell终端就会变成编辑界面,会多出Run菜单,选择运行即可,出现图形好激动,有没有哈。。。
(3)附:我的源码如下:
import numpy as np
import matplotlib.pyplot as plt
N = 5
menMeans = (20, 35, 30, 35, 27)
menStd = (2, 3, 4, 1, 2)
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)
womenMeans = (25, 32, 34, 20, 25)
womenStd = (3, 5, 2, 3, 3)
rects2 = ax.bar(ind+width, womenMeans, width, color='y', yerr=womenStd)
# add some
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind+width)
ax.set_xticklabels( ('G1', 'G2', 'G3', 'G4', 'G5') )
ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') )
def autolabel(rects):
# attach some text labels
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
plt.show()
相关文章推荐
- php文件下载
- SmtpClient 类
- ubuntu下配置NFS,TFTP服务
- PHP 依赖注入 (转)
- kuangbin_ShortPath R (HDU 4370)
- Matplotlib安装感想
- PHP中递归函数的一个常见逻辑问题
- 也说php从mysql数据库通过服务器端json返回数据出现乱码问题
- zend studio12.5破解方法
- PHP学习练手(十五)
- PHP 二进制 pack() unpack()
- PHP中VC6、VC9、TS、NTS版本的区别与用法详解
- 搭建个人博客&论坛(LAMP):wordpress、discuz、phpMyAdmin
- matplotlib 简介
- php cli模式学习(PHP命令行模式)
- 手把手搭建WAMP+PHP+SVN开发环境
- yii随笔(三) 开启友好路径
- php从A数据库中多张表读数据,插入到B数据库B表里面
- PHP与数据库
- php实现简单的上一页下一页