python中numpy模块用matplotlib画散点图折线图直方图

# 折线图/散点图 plot

# import matplotlib.pylab as pyl

# import numpy as np

# x = [1,2,3,4,8]

# y = [4,5,7,5,9]

#pyl.plot(x轴数据,y轴数据,展现形式)  #x,y轴必须数量相同、展现形式为,散点还是折线图,线的颜色等等,也可以不写

# pyl.plot(x,y)  #折线图

# pyl.plot(x,y,'o') #散点图,默认为这点图,第三个位置写'o'就是散点图

# pyl.show()

#更改散点颜色

'''

c-cyan-青色

r-red-红色

m-magente-品红

g-green-绿色

b-blue-蓝色

y-yellow-黄色

b-black-黑色

w-white-白色

'''

# pyl.plot(x,y,'ob')

# pyl.plot(x,y,'r')

# pyl.show()

# pyl.plot(x,y,'r')

#更改线条样式

'''

-直线

--虚线

-.-.

:细小虚线

'''

# pyl.plot(x,y,'--r')

# pyl.show()

#点的样式

'''

s--方形

h--六角形

H--六角形

*--星形

+--加号

xx-x形

d--菱形

D--菱形

p--五角形

'''

# pyl.plot(x,y,'*')

# pyl.show()

#加标题

# pyl.title("起的名字")

#加x轴名称

# pyl.xlabel('x轴名称')

#加y轴名称

# pyl.ylabel('y轴名称')

#加x,y轴范围

# pyl.xlim(0,20)

# pyl.ylim(5,18)

#设置俩条线

# x2 = [11,21,13,14,8]

# y2 = [14,15,7,5,9]

# pyl.plot(x2,y2)

# pyl.show()

#我们在写相关代码时总会有一些警告,虽然并不影响结果,但是很影响美观。如果在不急于解决警告的情况下我们可以选择一些方法进行忽略。

# import warnings

# warnings.filterwarnings("ignore", category=Warning)

# 随机数的生成

# data = np.random.random_integers(1,8,3)  #(最小值,最大值,个数)

# print(data)

#正态分布

# data2 = np.random.normal(5.0,2.0,10)#均数,西格玛,个数

# print(data2)

#直方图hist

import matplotlib.pylabas pyl

import numpyas np

# data3 = np.random.normal(10.0,1.0,10000)#均数,西格玛,个数

# pyl.hist(data3)

# pyl.show()

# data4 = np.random.random_integers(1,25,1000)  #(最小值,最大值,个数)

# pyl.hist(data4)

# pyl.show()

#设置直方图上下限和宽度

# data4 = np.random.random_integers(1,25,1000)  #(最小值,最大值,个数)

# sty = np.arange(2,17,4)  #(上限,下限,宽度)

# pyl.hist(data4,sty)  #pyl.hist(数据,设置的形式)

# pyl.show()

#取消轮廓

# data4 = np.random.random_integers(1,25,1000)  #(最小值,最大值,个数)

# sty = np.arange(2,17,4)  #(上限,下限,宽度)

# pyl.hist(data4,sty,histtype='stepfilled')  #pyl.hist(数据,设置的形式,histtype='stepfilled')  #histtype='stepfilled'可以放在任意位置

# pyl.show()

# 子图

# pyl.subplot(行,列,当前区域)

# pyl.subplot(2,2,3)

# pyl.show()

# 在子图中绘图

#2行,并且第一行2列第二行1列

#在谁下面写代码,图就是谁的

pyl.subplot(2,2,1)

x1=[1,2,3]

y1=[1,2,3]

pyl.plot(x1,y1)

pyl.subplot(2,2,2)

x2=[1,3,5]

y2=[11,22,13]

pyl.plot(x2,y2)

pyl.subplot(2,1,2)

pyl.show()

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容