1、折线图
import matplotlib as mlb from matplotlib import pylab as pl # 折线图 # 分别创建x,y坐标 x = [1,3,5,7,6,9,10,13,16] y = [3,4,5,7,9,0,1,2,3]
# 设置标题pl.title("plot of x ")
# 将坐标内容增加进表格 # 第三个参数是展示的颜色 pl.plot(x,y,'r') # 将图表展示 pl.show()
颜色参数与对应的颜色:
b:blue g:green r:red y:yellow k:black w:white
结果:
2、散点图
散点图的写法和折线图一致,只需要在颜色参数中增加o即可,eg:pl.plot(x, y)改成pl.plot(x, y, 'or')
3、柱状体的生成,用的是bar
from matplotlib import pylab as pl x = [1,3,5,7,6,9,10,13,16] y = [3,4,5,7,9,2,1,2,3] pl.title("bar of x ") pl.bar(x,y) pl.show()
结果:
4、饼状图,pie
from matplotlib import pylab as pl x = [7,6,9,10,13,16] pl.title("pie of x ") pl.pie(x) pl.show()
结果: