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
1 from matplotlib import pylab as pl 2 3 4 x = [1,3,5,7,6,9,10,13,16] 5 y = [3,4,5,7,9,2,1,2,3] 6 7 pl.title("bar of x ") 8 pl.bar(x,y) 9 10 pl.show()
结果:
4、饼状图,pie
1 from matplotlib import pylab as pl 2 3 4 x = [7,6,9,10,13,16] 5 6 pl.title("pie of x ") 7 pl.pie(x) 8 9 pl.show()
结果: