matplotlib2.02基本画图

来源:互联网 发布:丹爷辣椒酱淘宝 编辑:程序博客网 时间:2024/05/29 17:31

最近在使用matplotlib画图,最基本的内容

散点中的marker

marker description
“.” point
“,” pixel
“o” circle
“v” triangle_down
“^” triangle_up
“<” triangle_left
“>” triangle_right
“1” tri_down
“2” tri_up
“3” tri_left
“4” tri_right
“8” octagon
“s” square
“p” pentagon
“P” plus (filled)
“*” star
“h” hexagon1
“H” hexagon2
“+” plus
“x” x
“X” x (filled)
“D” diamond
“d” thin_diamond
“|” vline
“_” hline

线条形状linestyle

linestyle description
‘-’ or ‘solid’ solid line
‘–’ or ‘dashed’ dashed line
‘-.’ or ‘dashdot’ dash-dotted line
‘:’ or ‘dotted’ dotted line
‘None’ draw nothing
’ ’ draw nothing
” draw nothing

颜色

这里写图片描述

绘制最基本的图

#coding:utf-8"""python 3matplotlib 2.02"""import numpy as npimport matplotlib.pyplot as pltnp.random.seed(1) #随机种子x = np.linspace(0,1,100)noise = np.random.normal(0,0.1,100)y = 2*x + noiseplt.figure(1)plt.plot(x,y,linestyle='--',lw=2,c='c',label='test') #linestyle表示线条形状plt.legend(loc='best')plt.title('this is for matplotlib2.02 test')plt.grid(True)plt.figure(2)x1 = np.random.normal(1,1,300)x2 = np.random.normal(5,1,300)y1 = np.random.normal(1,1,300)y2 = np.random.normal(5,1,300)plt.scatter(x1,y1,c='seagreen',s=60,marker='*') #marker表示散点形状plt.scatter(x2,y2,c='peru',s=60,marker='1')plt.show()

这里写图片描述

这里写图片描述