标准的Python中用列表(list)保存一组值,可以当作数组使用。但由于列表的元素可以是任何对象,因此列表中保存的是对象的指针。这样一来,为了保存一个简单的列表[1,2,3],就需 
要有三个指针和三个整数对象。对于数值运算来说,这种结构显然比较浪费内存和 CPU 计算时间。

使用numpy的array模块可以解决这个问题。细节不在此赘述。这里主要记录一些matplotlib的基本使用方法

first plot
#first plot with matplotlib

import matplotlib.pyplot as plt

plt.plot([1,3,2,4])

plt.show()

in order to avoid pollution of global namespace, it is strongly recommended to never import like:

from import *

simple plot
import matplotlib as mpl

import matplotlib.pyplot as plt

import numpy as np

x = np.arange(0.0,6.0,0.1)

plt.plot(x, [xi**2 for xi in x],label = 'First',linewidth = 4,color = 'black')

plt.plot(x, [xi**2+2 for xi in x],label = 'second',color = 'red')

plt.plot(x, [xi**2+5 for xi in x],label = 'third')

plt.axis([0,7,-1,50])

plt.xlabel(r"$\alpha$",fontsize=20)

plt.ylabel(r'y')

plt.title('simple plot')

plt.legend(loc = 'upper left')

plt.grid(True)

plt.savefig('simple plot.pdf',dpi = 200)

print mpl.rcParams['figure.figsize']       #return 8.0,6.0

print mpl.rcParams['savefig.dpi']          #default to 100              the size of the pic will be 800*600

#print mpl.rcParams['interactive']

plt.show()

Python-3

Decorate plot with styles and types
import matplotlib as mpl

import matplotlib.pyplot as plt

import numpy as np

x = np.arange(0.0,6.0,0.1)

plt.plot(x, [xi**2 for xi in x],label = 'First',linewidth = 4,color = 'black')   #using color string to specify color

plt.plot(x, [xi**2+2 for xi in x],'r',label = 'second')                          #using abbreviation to specify color

plt.plot(x, [xi**2+5 for xi in x],color = (1,0,1,1),label = 'Third')             #using color tuple to specify color

plt.plot(x, [xi**2+9 for xi in x],color = '#BCD2EE',label = 'Fourth')             #using hex string to specify color

plt.xticks(np.arange(0.0,6.0,2.5))

plt.xlabel(r"$\alpha$",fontsize=20)

plt.ylabel(r'y')

plt.title('simple plot')

plt.legend(loc = 'upper left')

plt.grid(True)

plt.savefig('simple plot.pdf',dpi = 200)

print mpl.rcParams['figure.figsize']       #return 8.0,6.0

print mpl.rcParams['savefig.dpi']          #default to 100              the size of the pic will be 800*600

#print mpl.rcParams['interactive']

plt.show(

 
image

types of graph
  • 2


image

Bars

import matplotlib.pyplot as plt 

import numpy as np 

dict = {'A': 40, 'B': 70, 'C': 30, 'D': 85} 

for i, key in enumerate(dict): plt.bar(i, dict[key]);

plt.xticks(np.arange(len(dict))+0.4, dict.keys());

plt.yticks(dict.values());

plt.grid(True)

plt.show()


image_1

Pies

import matplotlib.pyplot as plt 

plt.figure(figsize=(10,10));

x = [4, 9, 21, 55, 30, 18] 

labels = ['Swiss', 'Austria', 'Spain', 'Italy', 'France', 

'Benelux'] 

explode = [0.2, 0.1, 0, 0, 0.1, 0] 

plt.pie(x, labels=labels, explode=explode, autopct='%1.1f%%'); 

plt.show()

image_2

Scatter

import matplotlib.pyplot as plt

import numpy as np

x = np.random.randn(12,20)

y = np.random.randn(12,20)

mark = ['s','o','^','v','>','<','d','p','h','8','+','*']

for i in range(0,12):

    plt.scatter(x[i],y[i],marker = mark[i],color =(np.random.rand(1,3)),s=50,label = str(i+1))

plt.legend()

plt.show()

matplotlib 常用操作的更多相关文章

  1. matplotlib常用操作2

    关于matplotlib学习还是强烈建议常去官方http://matplotlib.org/contents.html里查一查各种用法和toturial等. 下面是jupyter notebook代码 ...

  2. matplotlib常用操作

    1.根据坐标点绘制: import numpy as np import matplotlib.pyplot as plt x = np.array([1,2,3,4,5,6,7,8]) y = np ...

  3. 二叉树的python可视化和常用操作代码

    二叉树是一个重要的数据结构, 本文基于"二叉查找树"的python可视化 pybst 包, 做了一些改造, 可以支持更一般的"二叉树"可视化. 关于二叉树和二叉 ...

  4. 【三】用Markdown写blog的常用操作

    本系列有五篇:分别是 [一]Ubuntu14.04+Jekyll+Github Pages搭建静态博客:主要是安装方面 [二]jekyll 的使用 :主要是jekyll的配置 [三]Markdown+ ...

  5. php模拟数据库常用操作效果

    test.php <?php header("Content-type:text/html;charset='utf8'"); error_reporting(E_ALL); ...

  6. Mac OS X常用操作入门指南

    前两天入手一个Macbook air,在装软件过程中摸索了一些基本操作,现就常用操作进行总结, 1关于触控板: 按下(不区分左右)            =鼠标左键 control+按下        ...

  7. mysql常用操作语句

    mysql常用操作语句 1.mysql -u root -p   2.mysql -h localhost -u root -p database_name 2.列出数据库: 1.show datab ...

  8. nodejs配置及cmd常用操作

    一.cmd常用操作 1.返回根目录cd\ 2.返回上层目录cd .. 3.查找当前目录下的所有文件dir 4.查找下层目录cd window 二.nodejs配置 Node.js安装包及源码下载地址为 ...

  9. Oracle常用操作——创建表空间、临时表空间、创建表分区、创建索引、锁表处理

    摘要:Oracle数据库的库表常用操作:创建与添加表空间.临时表空间.创建表分区.创建索引.锁表处理 1.表空间 ■  详细查看表空间使用状况,包括总大小,使用空间,使用率,剩余空间 --详细查看表空 ...

随机推荐

  1. python安装脚本

    [root@dn3 hadoop]# cat install.py #!/usr/bin/python #coding=utf- import os import sys : pass else: p ...

  2. minhash pyspark 源码分析——hash join table是关键

    从下面分析可以看出,是先做了hash计算,然后使用hash join table来讲hash值相等的数据合并在一起.然后再使用udf计算距离,最后再filter出满足阈值的数据: 参考:https:/ ...

  3. wordpress实现主动推送+熊掌号推送同步进行

    今天给一个朋友http://www.myunigift.cn/ 这个站点是用wordpress,今天帮他改造熊掌号,于是做了数据同步推送. 只要把下面的代码写到funtions.php里面,发布文章的 ...

  4. 常用的HTTP状态码,网站开发请求状态必备

    成功的状态码: 200 – 服务器成功返回网页 304 – 未修改 失败的状态码: 404 – 请求的网页不存在 503 – 服务器暂时不可用 500 – 服务器内部错误 下面的不是很常用,记住上面那 ...

  5. Dubbo源码分析:Dubbo协议解码

    Dubbo协议解码时序图

  6. VOJ 1049送给圣诞夜的礼物——矩阵快速幂模板

    题意 顺次给出 $m$个置换,反复使用这 $m$ 个置换对一个长为 $n$ 初始序列进行操作,问 $k$ 次置换后的序列.$m<=10, k<2^31$. 题目链接 分析 对序列的置换可表 ...

  7. [Kubernetes] Pod Health

    Kubernetes relies on Probes to determine the health of a Pod container. A Probe is a diagnostic perf ...

  8. mongodb 集群配置文件

    本文档是在mongodb为3.4下编写的,仅作为参考,详细内容请参考:https://docs.mongodb.com/manual/reference/configuration-options/# ...

  9. 【JS】知识笔记

    一.JS文件位置 多个.JS文件最好合并到一个文件中,减少加载页面时发送的请求数量. 某个单独页面需要的js,最好放在HTML文档的最后,</body>之前,这样能使浏览器更快地加载页面. ...

  10. Pytest权威教程16-经典xUnit风格的setup/teardown

    目录 经典xUnit风格的setup/teardown 模块级别setup/teardown 类级别setup/teardown 方法和函数级别setup/teardown 返回: Pytest权威教 ...