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 画图的更多相关文章

  1. python matplotlib画图产生的Type 3 fonts字体没有嵌入问题

    ScholarOne's 对python matplotlib画图产生的Type 3 fonts字体不兼容,更改措施: 在程序中添加如下语句 import matplotlib matplotlib. ...

  2. python matplotlib 画图

    import numpy as np import matplotlib.pyplot as plt from pylab import * numpy 常用来组织源数据: 使用 plot 函数直接绘 ...

  3. 使用python中的matplotlib 画图,show后关闭窗口,继续运行命令

    使用python中的matplotlib 画图,show后关闭窗口,继续运行命令 在用python中的matplotlib 画图时,show()函数总是要放在最后,且它阻止命令继续往下运行,直到1.0 ...

  4. python使用matplotlib画图

    python使用matplotlib画图 matplotlib库是python最著名的画图库.它提供了一整套和matlab类似的命令API.十分适合交互式地进行制图. 先介绍了怎样使用matplotl ...

  5. python使用matplotlib画图,jieba分词、词云、selenuium、图片、音频、视频、文字识别、人脸识别

    一.使用matplotlib画图 关注公众号"轻松学编程"了解更多. 使用matplotlib画柱形图 import matplotlib from matplotlib impo ...

  6. 使用Python matplotlib做动态曲线

    今天看到“Python实时监控CPU使用率”的教程: https://www.w3cschool.cn/python3/python3-ja3d2z2g.html 自己也学习如何使用Python ma ...

  7. matplotlib 画图

    matplotlib 画图 1. 画曲线图       Tompson = np.array([0, 0, 0, 0, 0.011, 0.051, 0.15, 0.251, 0.35, 0.44, 0 ...

  8. matplotlib画图

    matplotlib画图 import numpy as np import matplotlib.pyplot as plt x1=[20,33,51,79,101,121,132,145,162, ...

  9. python seaborn 画图

    python seaborn 画图 59888745@qq.com 2017.08.02 distplot( )  kdeplot( ) distplot( )为hist加强版, kdeplot( ) ...

随机推荐

  1. c# MVC在WEB.Config中配置MIME

    在IIS中,默认没有添加.json格式的MIME,所有无法读取服务器中的.json格式的文件,返回结果404 方式一:在IIS中手动添加MIME 1.点击MIME进入MIME列表 2.添加MIME 3 ...

  2. ROS TF——learning tf

    在机器人的控制中,坐标系统是非常重要的,在ROS使用tf软件库进行坐标转换. 相关链接:http://www.ros.org/wiki/tf/Tutorials#Learning_tf 一.tf简介 ...

  3. ubnutu安装sougou 输入法

    先安百度经验安装fcitx 1.首先下载sogoupinyin_2.0.0.0068_amd64.deb,点击安装后,会通过ubuntu软件中心安装,安装玩成后,任然是无法使用.然后: 2.然后执行下 ...

  4. mongoose

    var mongoose = require('mongoose');mongoose.connect('mongodb://localhost/test'); var Cat = mongoose. ...

  5. Android Phonebook编写联系人UI加载及联系人保存流程(六)

    2014-01-07 11:18:08 将百度空间里的东西移过来. 1. Save contact 我们前面已经写了四篇文章,做了大量的铺垫,总算到了这一步,见证奇迹的时刻终于到了. 用户添加了所有需 ...

  6. This absolute uri http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application

    部署生产环境出现以上错误,原因是jsp页面中使用了jstl的标签,但没有导入相应的jar包.因为开发环境 myeclipse10 自带类库已经集成 解决方法 ①将jstl.jar和standard.j ...

  7. PL/SQL : Procedural Language / Structual Query Language and it is an exrension to SQL.

    SQL is not very flexible and it cannot be made to react differently to differing sutuations easily. ...

  8. [转] Linux内核代码风格 CodingStyle [CH]

    from:http://blog.csdn.net/jiang_dlut/article/details/8163731 中文版维护者: 张乐 Zhang Le <r0bertz@gentoo. ...

  9. php操作文件(读取写入文件)

    一,PHP如何读取文件 PHP读取文件可以读取当前服务器或远程服务器中的文件.其步骤是:打开文件.读文件和关闭文件. 1,PHP如何打开文件 使用PHP函数fopen()打开一个文件,fopen()一 ...

  10. Unity4.3.3激活

    Unity4.X Win版本的破解方法: <ignore_js_op> 1.安装unity4.X,一路按提示下一步,要断网,直到激活运行软件后再联网2.将Unity 4.x Pro Pat ...