Python之matplotlib模块安装
numpy
1、下载安装
源代码
http://sourceforge.net/projects/numpy/files/NumPy/
安装
python2.7 setup.py install
2、测试
导入numpy模块,出现如下错误:
[root@typhoeus79 numpy-1.8.0]# python2.7
Python 2.7.3 (default, Nov 27 2012, 17:47:24)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "numpy/__init__.py", line 143, in <module>
raise ImportError(msg)
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
>>>
原因是在源代码安装的地方进行测试,当前目录有如下文件:
[root@typhoeus79 numpy-1.8.0]# ll
drwxr-xr-x 18 501 games 4096 Nov 13 17:57 numpy
换个目录就ok了
>>> import numpy
>>> print numpy.__version__
1.9.0.dev-4d0076f
matplotlib
1、安装准备
需要安装six模块
https://pypi.python.org/simple/six/
作用:
Six is a Python 2 and 3 compatibility library. It provides utility functions
for smoothing over the differences between the Python versions with the goal of
writing Python code that is compatible on both Python versions. See the
documentation for more information on what is provided.
需要安装pyparsing
http://pyparsing.wikispaces.com/Download+and+Installation
说明:
The pyparsing module is an alternative approach to creating and executing
simple grammars, vs. the traditional lex/yacc approach, or the use of
regular expressions. The pyparsing module provides a library of classes
that client code uses to construct the grammar directly in Python code. Here is a program to parse "Hello, World!" (or any greeting of the form
"<salutation>, <addressee>!"): from pyparsing import Word, alphas
greet = Word( alphas ) + "," + Word( alphas ) + "!"
hello = "Hello, World!"
print hello, "->", greet.parseString( hello ) The program outputs the following: Hello, World! -> ['Hello', ',', 'World', '!']
2、安装matplotlib
http://sourceforge.net/projects/matplotlib/?source=dlp
python2.7 setup.py install
>>> import matplotlib
>>> print matplotlib.__version__
1.3.1
http://matplotlib.org/1.3.1/api/pyplot_summary.html
3、例子
代码:
"""
This example shows how to use a path patch to draw a bunch of
rectangles for an animated histogram
"""
import numpy as np import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.path as path
import matplotlib.animation as animation fig, ax = plt.subplots() # histogram our data with numpy
data = np.random.randn(1000)
n, bins = np.histogram(data, 100) # get the corners of the rectangles for the histogram
left = np.array(bins[:-1])
right = np.array(bins[1:])
bottom = np.zeros(len(left))
top = bottom + n
nrects = len(left) # here comes the tricky part -- we have to set up the vertex and path
# codes arrays using moveto, lineto and closepoly # for each rect: 1 for the MOVETO, 3 for the LINETO, 1 for the
# CLOSEPOLY; the vert for the closepoly is ignored but we still need
# it to keep the codes aligned with the vertices
nverts = nrects*(1+3+1)
verts = np.zeros((nverts, 2))
codes = np.ones(nverts, int) * path.Path.LINETO
codes[0::5] = path.Path.MOVETO
codes[4::5] = path.Path.CLOSEPOLY
verts[0::5,0] = left
verts[0::5,1] = bottom
verts[1::5,0] = left
verts[1::5,1] = top
verts[2::5,0] = right
verts[2::5,1] = top
verts[3::5,0] = right
verts[3::5,1] = bottom barpath = path.Path(verts, codes)
patch = patches.PathPatch(barpath, facecolor='green', edgecolor='yellow', alpha=0.5)
ax.add_patch(patch) ax.set_xlim(left[0], right[-1])
ax.set_ylim(bottom.min(), top.max()) def animate(i):
# simulate new data coming in
data = np.random.randn(1000)
n, bins = np.histogram(data, 100)
top = bottom + n
verts[1::5,1] = top
verts[2::5,1] = top ani = animation.FuncAnimation(fig, animate, 100, repeat=False) plt.savefig("./test.png") #测试环境属于CentOS release 5.4非界面版
#plt.show() #故show不出来
结果:
3、ipython
ipython 是一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell 命令,内置了许多很有用的功能和函数。
https://github.com/ipython/ipython
[root@typhoeus79 20131113]# ipython
Python 2.4.3 (#1, Sep 3 2009, 15:37:37)
Type "copyright", "credits" or "license" for more information. IPython 0.8.4 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more. In [1]: %pycat test.
test.png test.py test.txt In [1]: %pycat test.txt
test ipython
从python版本看还是2.4.3,使用python2.7 setup.py install安装之后再次调用出现如下警告:
/usr/local/sinasrv2/lib/python2.7/site-packages/IPython/utils/path.py:424: UserWarning: Found old IPython config file u'/root/.ipython/ipy_user_conf.py' (modified by user)
将/root/.ipython移走即可。
Python之matplotlib模块安装的更多相关文章
- Python的第三方模块安装
python的第三方模块安装一般使用python自带的工具pip来安装. 1.在Windows下,在安装python时勾选[安装pip]和[添加python至环境变量]. 如果在python安装目录的 ...
- python之 matplotlib模块之基本三图形(直线,曲线,直方图,饼图)
matplotlib模块是python中一个强大的绘图模块 安装 pip install matplotlib 首先我们来画一个简单的图来感受它的神奇 import numpy as np impo ...
- Python的MySQLdb模块安装,连接,操作,增删改
1. 首先确认python的版本为2.3.4以上,如果不是需要升级python的版本 python -V 检查python版本 2. 安装mysql, 比如安装在/usr/local/my ...
- yum安装memcache,mongo扩展以及python的mysql模块安装
//启动memcached/usr/local/memcached/bin/memcached -d -c 10240 -m 1024 -p 11211 -u root/usr/local/memca ...
- python之mysqldb模块安装
之所以会写下这篇日志,是因为安装的过程有点虐心.目前这篇文章是针对windows操作系统上的mysqldb的安装.安装python的mysqldb模块,首先当然是找一些官方的网站去下载:https:/ ...
- Python使用matplotlib模块绘制多条折线图、散点图
用matplotlib模块 #!usr/bin/env python #encoding:utf-8 ''' __Author__:沂水寒城 功能:折线图.散点图测试 ''' import rando ...
- Python中matplotlib模块解析
用Matplotlib绘制二维图像的最简单方法是: 1. 导入模块 导入matplotlib的子模块 import matplotlib.pyplot as plt import numpy as ...
- Python的MySQLdb模块安装
MySQL-python-1.2.1.tar.gz 下载地址:https://pan.baidu.com/s/1kVfH84v 然后解压,打开README(这个其实没有什么鸟用) 里面有安装过程: ...
- python之路-模块安装 paramiko
paramiko介绍(全是洋文,看不懂啊,赶紧有道翻译吧,等有朝一日,我去报个华尔街): "Paramiko" is a combination of the esperanto ...
随机推荐
- 我从.net转别的语言的遭遇,现在貌似又要回头(一)
从2016年开始,作为公司最后的一个.net部门,被迫转向了php. php里面装得一手什么逼呢? 首先,你要来几本入门的书,linux,mysql,php基础语法,nginx或apache.哥那时候 ...
- cocos2dx - 生成怪物及AI
接上一节内容:cocos2dx - tmx地图分层移动处理 本节怪物及简单AI实现 一.怪物 同cocos2dx - v2.3.3编辑器骨骼动画 里创建的CPlalyer一样,新建一个CMonster ...
- Linux系列教程(二)——Linux系统安装(手把手学安装centos6.8)
在上一篇博客我们简单的介绍了Linux系统的起源,这篇博客我们将通过图示一步一步教大家如何安装Linux系统.注意这里我们选择安装的Linux系统是其一种发行版本 CentOS,这里给大家普及一个概念 ...
- 无限大地图:lightmap拆分
无缝地图涉及到地形.物件的分块加载,同样,lightmap也需要动态加载.而场景烘焙时,所有物件都是一起烘焙的,那怎么把某些物件指定烘焙到某一张lightmap贴图中?网上找了很久,也没有看到具体的实 ...
- C语言第一次实验报告
一.实验题目,设计思路,实现方法 7-7 计算火车运行时间(15 分) 4-5 求简单交错序列前N项和(15 分) 4-2-7 装睡(10 分) 思路:7-7须将时间统一单位,化为以分钟计算再将两者相 ...
- GoldenGate 复制进程报错"OGG-01296 Error mapping",丢弃文件报错“Mapping problem with delete record (target format)”,且实际条目存在
故障描述: (1).复制进程 Abended,通过view report语句查看可发现类似如下的报错: 2017-10-23 15:01:43 ERROR OGG-01296 Error mappin ...
- (转)JVM性能调优之生成堆的dump文件
转自:http://blog.csdn.net/lifuxiangcaohui/article/details/37992725 最近因项目存在内存泄漏,故进行大规模的JVM性能调优 , 现把经验做一 ...
- ADO.NET生成的数据库连接字符串解析
1.概述 当我们使用ADO.NET数据实体模型生成的时候,在项目目下生成一个.edmx文件的同时,还会在app.config里面出现如下一个代码串: <?xml version="1. ...
- C#设计模式之十组合模式(Composite)【结构型】
一.引言 今天我们要讲[结构型]设计模式的第四个模式,该模式是[组合模式],英文名称是:Composite Pattern.当我们谈到这个模式的时候,有一个物件和这个模式很像,也符合这个模式要表达 ...
- LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal (用中序和后序树遍历来建立二叉树)
Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...