matplotlib基础 折线图、散点图

折线图/散点图plot、直方图hist

import matplotlib.pylab as pyl

pyl.plot(x,y) # plot(x轴数据,y轴数据,展现形式)

#pyl.plot(x,y,‘oy’) # '0’散点图 'oy’黄色散点图

pyl.show()

‘’’
c - cyan -青色
r -red -红色
m - magente -品红
g 绿色
b 蓝色
k black 黑色
w 白色
‘’’
# 线条样式
‘’’
-直线
–虚线
-。
:细小虚线
‘’’

_____________________________________________________-

‘’’
x1 = [1,2,3,4,5]
y1 = [7,8,9,4,5]
pyl.plot(x1,y1,’–’)

x2 = [1,6,3,5,4,9] # 同一幅图多条线段
y2 = [5,9,9,9,9,9]
pyl.plot(x2,y2,’-.’)

pyl.title(‘sss’) #表头
pyl.xlabel(“age”)
pyl.ylabel(‘temp’)
pyl.xlim(0,20) #x,y轴取值范围
pyl.ylim(0,10)

#pyl.show()
‘’’

 # 点的样式

‘’’
s - 方形
h、H - 六角形
* - 星形
+ - 加号形
d、D -菱形
p - 五角形

‘’’

___________________________________________________________

 #  随机数的生成   http://www.mamicode.com/info-detail-507676.html

import numpy as np
#data = np.random.random_integers(1,20,1000) # (最小值,最大值,个数)
#print(data)
#正态random.normal

data1 = np.random.normal(5.0,2.0,10000000) # μ,西格玛,个数

pyl.hist(data1)

pyl.show()

#随机正整数 random_integers
‘’’
data2 = np.random.random_integers(1,25,1000)
pyl.hist(data2)

设置形式

sty = np.arange(1,50,4) # (起,终,步长)类似range
pyl.hist(data2,sty,histtype=“stepfilled”) # 取消轮廓histtype=“stepfilled”
pyl.show()
‘’’

_____________________________________________

子图

pyl.subplot(2,2,1) # 行 列 当前区域
x1 = [1,2,3,4,5]
y1 = [5,6,4,5,6]
pyl.plot(x1,y1,‘oy’)

pyl.subplot(2,2,2)
x2 = [1,2,5,6]
y2 = [2,4,5,6]
pyl.plot(x2,y2,‘H’)

pyl.subplot(2,1,2)
x3 = [4,4,4,4,4,4,4]
y3 = [6,4,5,2,1,2,1]
pyl.plot(x3,y3,“p”)

pyl.show()

猜你喜欢

转载自blog.csdn.net/qq_43487620/article/details/88046202
今日推荐