matplotlib是python的一个开源的2D绘图库,它的原作者是John D. Hunter,因为在设计上借鉴了matlab,所以成为matplotlib。和Pillow一样是被广泛使用的绘图功能,而在深度学习相关的部分,matplotlib得宠的多。这篇文章将简单介绍一下如何安装以及使用它来画一些非常常见的统计图形。
概要信息
注意事项:由于Python2支持到2020年,很多python库都开始主要支持python3了,matplotlib的主分支也已经是python3了。而这篇文章中为了简单,安装和demo代码依然是在python2.7上进行验证的。
安装
使用pip install即可直接安装。安装日志如下:
liumiaocn:tmp liumiao$ python -mpip install -U pip
Requirement already up-to-date: pip in /usr/local/lib/python2.7/site-packages (10.0.1)
liumiaocn:tmp liumiao$
liumiaocn:tmp liumiao$ python -mpip install -U matplotlib
Collecting matplotlib
Downloading https://files.pythonhosted.org/packages/61/38/d70e8bf77d5cb27d5f3595edd0b3978825063feadd023786d2591e393e6e/matplotlib-2.2.2-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (13.7MB)
100% |████████████████████████████████| 13.7MB 2.1MB/s
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/6a/8a/718fd7d3458f9fab8e67186b00abdd345b639976bc7fb3ae722e1b026a50/pyparsing-2.2.0-py2.py3-none-any.whl (56kB)
100% |████████████████████████████████| 61kB 5.8MB/s
Collecting backports.functools-lru-cache (from matplotlib)
Downloading https://files.pythonhosted.org/packages/03/8e/2424c0e65c4a066e28f539364deee49b6451f8fcd4f718fefa50cc3dcf48/backports.functools_lru_cache-1.5-py2.py3-none-any.whl
Collecting subprocess32 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/fa/60/b50459f291cae6bc1d0ff711b75e5130684fd3949370fdba78f6c57c1903/subprocess32-3.5.2-cp27-cp27m-macosx_10_6_intel.whl
Collecting pytz (from matplotlib)
Downloading https://files.pythonhosted.org/packages/dc/83/15f7833b70d3e067ca91467ca245bae0f6fe56ddc7451aa0dc5606b120f2/pytz-2018.4-py2.py3-none-any.whl (510kB)
100% |████████████████████████████████| 512kB 8.9MB/s
Requirement not upgraded as not directly required: six>=1.10 in /usr/local/lib/python2.7/site-packages (from matplotlib) (1.11.0)
Collecting python-dateutil>=2.1 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/cf/f5/af2b09c957ace60dcfac112b669c45c8c97e32f94aa8b56da4c6d1682825/python_dateutil-2.7.3-py2.py3-none-any.whl (211kB)
100% |████████████████████████████████| 215kB 7.2MB/s
Collecting kiwisolver>=1.0.1 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/79/d8/94633718f3f77dcb638687a77ba199325a1cb158d2d4b00c9dc17f2b5c72/kiwisolver-1.0.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (110kB)
100% |████████████████████████████████| 112kB 5.9MB/s
Collecting cycler>=0.10 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/f7/d2/e07d3ebb2bd7af696440ce7e754c59dd546ffe1bbe732c8ab68b9c834e61/cycler-0.10.0-py2.py3-none-any.whl
Requirement not upgraded as not directly required: numpy>=1.7.1 in /usr/local/lib/python2.7/site-packages (from matplotlib) (1.14.5)
Requirement not upgraded as not directly required: setuptools in /usr/local/lib/python2.7/site-packages (from kiwisolver>=1.0.1->matplotlib) (39.2.0)
Installing collected packages: pyparsing, backports.functools-lru-cache, subprocess32, pytz, python-dateutil, kiwisolver, cycler, matplotlib
Successfully installed backports.functools-lru-cache-1.5 cycler-0.10.0 kiwisolver-1.0.1 matplotlib-2.2.2 pyparsing-2.2.0 python-dateutil-2.7.3 pytz-2018.4 subprocess32-3.5.2
liumiaocn:tmp liumiao$