首页 > 代码库 > Python-绘图

Python-绘图

import pylab  (or matplotlib.pyplot) as pl   

创建图表

pl.figure(1)    # 创建图表一

pl.figure(2)    # 创建图表二

······

sub_fig_211 = pl.subplot(211)    # 在图表中创建子图

sub_fig_212 = pl.subplot(212)    # 在图表中创建子图, 图2子图:第1列第2行

通过pl.figure(1)   pl.sca(sub_fig_212)  来选取图表和子图

绘图

pl.plot(x1, y1, ‘r‘)    pl.plot(x2, y2, ‘b‘)

pl.xlim(0, 100)    # x轴范围

pl.ylim(0, 100)    # y轴范围

标题&坐标轴

pl.tilte("figure title")    # 标题

pl.xlabel("x axis label")    # x 轴标注

pl.ylabel("y axis label")    # y 轴标注

 

 

颜色

pl.plot(x2, y2, ‘b‘)

颜色
 b  blue 蓝色
 c  cyan 蓝绿色
 g  green 绿色
 k  black 黑色
 m  magenta 品红色
 r  red 红色
 y  yellow 黄色
 w  white 白色

 

 

 

 

 

线条样式

pl.plot(x2, y2, ‘b--‘)

"-" "--" "-." ":" "None" " " ""
线型 solid 实线 dashed 虚线 dash_dot 虚线+点 dotted 点 nothing nothing nothing

 

 

 Show

pl.sca(sub_fig_212)

pl.plot(x2, y2, ‘g--‘)

pl.show()

 

Python-绘图