用python matplotlib 画图
state-machine environment
object-oriente interface
figure and axes
backend and frontend
user interface bankends
hardcopy backends or non-interactive backends
confugure your backends
renderer : AGG
import matplotlib.pyplot as plt
plt.plot() 可一次画好几个, return al list of lines.
b-, ro, bo, k, r--, bs, g^, g-, go-, o, -, r, r+, rs
- solid line
-- dashed line
-. dash-dot line
: dotted line
. point marker
, pixel marker
o cercle marker
v triangle_down marker
^ triangle_up marker
< triangle_left marker
> triangle_right marker
1 2 3 4 试试什么形状
s square marker
p pentagon marker
* star marker
h H
+ plus marker
D diamond marker
d thin_diamond marker
| vline marker
- hline marker
b blue
g green
r red
c cyan
m magenta
y yellow
k black
w white
linewidth = 2.0,
label = 'line 1'
legend() 会根据你的线的label 生成,如果你设置每个line的label的话
line, = plt.plot(x, y, '-')
line就是这个线对象, 方法有:set_antialiased(False),
plt.setp(lines, color='r', linewidth=2.0) 这是keyword args.
或
plt.setp(lines, 'color', 'r', 'linewidth', 2.0) 这是MATLAB style, string value pairs
关于lines properties, 还有很多。可以用plt.setp(lines) 来看, 看看lw=2 什么意思
plt.axis([x-st, x-end, y-st, y-end]) #这个要放到plt.savefig()的最前面, 要不不起作用。。。
plt.ylabel()
plt.show()
plt.savefig() #如果出现could not open display 的错误,将配置文件matplotlibrc复制到工作目录, 然后将backend改为AGG,服务器中配置文件位于/usr/lib64/python2.6/site-packages/matplotlib/mpl-data/matplotlibrc
gca()返回current axes
gcf() 返回current figure
plt.figure(1) #可以不用写,因为如果你不指定的话,figure(1) 和subplot(1,1,1) 都是默认创建的
参数有figsize = (x,y)
plt.subplot(211) # 当前是figure1的subplot 211
plt.plot(x1, f(x1), x2, 'bo', f(x2), 'k' )
plt.subplot(212) #当前是figure1 的subplot 212
plt.plot(x, f(x), 'r--')
subplot(rows, cols, fignum), 所以一共有rows*cols个图, fignum 指定是第几个
如果想更个性的话,用axes(left, bottom, width, height) 每个值都介于0和1之间。
clf() clear current figure
cla() clear current axes
the mamory required for a figure is not completely realeased until the figure is closed with close()
plt.text() 可以让你在图的任意位置加上文字信息。 plt.xlabel(), plt.ylabel(), plt.title() 在指定位置加文字信息。
just as with lines above, you can customize the propertied by passing keyword arguments into the text functions or using setp()
eg: plt.xlebel('hehe', fontsize=14, color='red')
plt.grid(True) 默认是False
plt.annotate('luanqibazaodezhushi', xy=(2,1), xytext=(3, 1.5), arrowprops=dict(facecolor='black', shrink=0.05),) 加上注释文本
pltylim(-2, -2)
一下是一个做柱状图的例子, 从中我们可以看到,axes对象的方法有:
bar(), 可以设置color='coral', label='1/1'...
legend()将上面有label的提取出来
set_xticks() 设置x-axis的坐标
set_xticklabels()
set_xlabel('hehe', fontsize=30), 可以设置fontsize=30, 对x-axis的说明
set_ylabel(),同set_xlabel, 也可以设置字体大小
set_title(), 也有fontsize设置字体大小
用面向对象的方法更能控制图形,而不是依靠状态环境。
fig = plt.figure(1, figsize=(12,6))
ax = fig.add_subplot(111)
ax.bar(每个bar的起始点,数组代表高度, 每个bar的宽度, *kwargs)
宽度width即可以是一个固定值,即所有的bar都用这个值,也可以是一个数组,不同的bar对应不同的值。
ax.set_xticks(数组) # 坐标, 一般在每个bar的中间部位
ax.set_xticklabels(数组) #坐标上的说明信息, 对这个bar的一个说明
ax.set_xlabel('Country')
ax.set_ylabel('GDP')
ax.set_title('Top 10 GDP Country', bbox={'facecolor':'0.8', 'pad':5})
plt.show()
例:
https://github.com/freemao/call-base-each-snp-site/blob/master/line_plot.py
https://github.com/freemao/call-base-each-snp-site/blob/master/bar_plot.py
by freemao
FAFU
free_mao@qq.com
用python matplotlib 画图的更多相关文章
- python matplotlib画图产生的Type 3 fonts字体没有嵌入问题
ScholarOne's 对python matplotlib画图产生的Type 3 fonts字体不兼容,更改措施: 在程序中添加如下语句 import matplotlib matplotlib. ...
- python matplotlib 画图
import numpy as np import matplotlib.pyplot as plt from pylab import * numpy 常用来组织源数据: 使用 plot 函数直接绘 ...
- 使用python中的matplotlib 画图,show后关闭窗口,继续运行命令
使用python中的matplotlib 画图,show后关闭窗口,继续运行命令 在用python中的matplotlib 画图时,show()函数总是要放在最后,且它阻止命令继续往下运行,直到1.0 ...
- python使用matplotlib画图
python使用matplotlib画图 matplotlib库是python最著名的画图库.它提供了一整套和matlab类似的命令API.十分适合交互式地进行制图. 先介绍了怎样使用matplotl ...
- python使用matplotlib画图,jieba分词、词云、selenuium、图片、音频、视频、文字识别、人脸识别
一.使用matplotlib画图 关注公众号"轻松学编程"了解更多. 使用matplotlib画柱形图 import matplotlib from matplotlib impo ...
- 使用Python matplotlib做动态曲线
今天看到“Python实时监控CPU使用率”的教程: https://www.w3cschool.cn/python3/python3-ja3d2z2g.html 自己也学习如何使用Python ma ...
- matplotlib 画图
matplotlib 画图 1. 画曲线图 Tompson = np.array([0, 0, 0, 0, 0.011, 0.051, 0.15, 0.251, 0.35, 0.44, 0 ...
- matplotlib画图
matplotlib画图 import numpy as np import matplotlib.pyplot as plt x1=[20,33,51,79,101,121,132,145,162, ...
- python seaborn 画图
python seaborn 画图 59888745@qq.com 2017.08.02 distplot( ) kdeplot( ) distplot( )为hist加强版, kdeplot( ) ...
随机推荐
- Floyd 算法的动态规划本质
[转载自:http://www.cnblogs.com/chenying99/p/3932877.html] Floyd–Warshall(简称Floyd算法)是一种著名的解决任意两点间的最短路径(A ...
- 知名杀毒软件Mcafee(麦咖啡)个人版 资源汇总兼科普(来自卡饭)
虽然早已不是用咖啡了,但我也实时关注的咖啡的一举一动,潜水看帖日久,发现小白众多,好多有价值的帖子淹没于帖海当中,甚是惋惜. 我有如下建议 1.咖啡区管理层,能否吧一些优秀的资源教程 ...
- hdu 4607 Park Visit
http://acm.hdu.edu.cn/showproblem.php?pid=4607 先求树的直径 方法:两遍bfs ,任选一点 a 求到a点最远的一点b ,然后 求到b点最远点 c 这样 ...
- BindingNavigator操作DatagridView的数据
参考 http://wenku.baidu.com/link?url=NWfEfArPZvDO_aI-xEKBHVGoZY9wQO_Oty_GCsGLiPspheCzFYLf_dytuWAqN2_0A ...
- IBatis.Net 表连接查询(五)
IBatis.Net之多表查询: 一.定制实际对应类的方式 首先配置多表的测试数据库,IBatis.Net之Oracle表连接查询配置: 首先新建两张表如下: 为两张表建立外键: ALTER TABL ...
- ubuntu 14.04 安装截图工具 Shutter及使用
一.安装截图工具 Shutter 1. 添加安装包软件源 sudo add-apt-repository ppa:shutter/ppa 1 2. 更新源并安装 shutter sudo apt-ge ...
- nginx查看配置文件nginx.conf路径
当你执行 nginx -t 得时候,nginx会去测试你得配置文件得语法,并告诉你配置文件是否写得正确,同时也告诉了你配置文件得路径: # nginx -t nginx: the configu ...
- mysql数据库 安装 (原创)
1.首先下载mysql 数据库,我安装的是mysql5.1版本,直接安装就行,但是如果以后你想在数据库里显示中文的话,要把字符集设置为gb2312 2.配置数据源odbc. mysql-connec ...
- 第二周 PSP项目计划
项目计划总结: 日期|任务 听课 编写程序 阅读相关书籍 网上查找资料 日总计 周一 2 1 2 5 周二 1 1 周三 2 2 周四 2 2 4 周五 ...
- “System.Threading.ThreadAbortException”类型的第一次机会异常在 mscorlib.dll 中发
问题原因: Thread.Abort 方法 .NET Framework 4 其他版本 1(共 1)对本文的评价是有帮助 - 评价此主题 在调用此方法的线程上引发 ThreadAbortExce ...