# -*- coding: utf-8 -*-
importnumpyasnp
importmatplotlib.pyplotasplt
importmatplotlib.datesasmdates
##########简单线型图
# plt.plot([1,3],[3,1])
# plt.show()
#########################################
################散点图
#不相关
# height=[161,170,182,175,173,165]
# weight=[50,58,80,70,69,55]
# plt.scatter(height,weight)
# plt.show()
############################
# N=1000
# x=np.random.randn(N)
# y1=np.random.randn(N)
# plt.scatter(x,y1)
# plt.show()
######################################股票价格指数
# open,close=np.loadtxt('000001.csv',delimiter=',',skiprows=1,usecols=(1,4),unpack=True)
# change=open-close
# yesterday=change[:-1]
# today=change[1:]
# plt.scatter(yesterday,today,s=500,c='r',marker='<',alpha=0.5)
# plt.show()
#########################################折线图
# x=np.linspace(-10,10,10)
# y=x**2
# plt.plot(x,y)
# plt.show()
####################################股票序列折线图
# date,open,close=np.loadtxt('000001.csv',delimiter=',',skiprows=1,converters={0:mdates.strpdate2num('%m/%d/%Y')},usecols=(0,1,4),unpack=True)
# plt.plot_date(date,open,linestyle='-',color='green',marker='<')
# plt.plot_date(date,close,linestyle='--',color='red',marker='<')
# plt.show()
#################################################条形图
#纵项条形图
# N=5
# y=[20,10,30,25,15]
# index=np.arange(N)
# pl=plt.bar(left=index,height=y,width=0.8,color='red')
# plt.show()
#横向条形图
# N=5
# y=[20,10,30,25,15]
# index=np.arange(N)
# #pl=plt.bar(left=0,bottom=index,height=0.5,width=y,color='red',orientation='horizontal')
# pl=plt.barh(left=0,bottom=index,width=y,height=0.5)
# plt.show()
########################################################双向并列图
# index=np.arange(4)
# sale_BJ=[52,55,63,53]
# sale_SH=[44,66,55,41]
# bar_width=0.3
# plt.bar(index,sale_BJ,bar_width,color='b')
# plt.bar(index+bar_width,sale_SH,bar_width,color='red')
# plt.show()
#######################################################################双向层叠图
# index=np.arange(4)
# sale_BJ=[52,55,63,53]
# sale_SH=[44,66,55,41]
# bar_width=0.3
# plt.bar(index,sale_BJ,bar_width,color='b')
# plt.bar(index,sale_SH,bar_width,color='r',bottom=sale_BJ)
# plt.show()
##################################################直方图
# mu=100
# sigma=20
# x=mu+sigma*np.random.randn(2000)
# #plt.hist(x,bins=50,color='red',normed=True)
# plt.hist(x,bins=10000,color='green',normed=False)
# plt.show()
###################################################33饼状图
# labels=['A','B','C','D']
# fracs=[15,30,45,10]
# plt.axes(aspect=1) #使得饼状图为圆形,而不为椭圆
# explod=[0,0,0.05,0]#突出某一重点
# plt.pie(x=fracs,labels=labels,autopct='%0.f%%',explode=explod,shadow=True)
# plt.show()0
#############################################箱形图
# np.random.seed(100)
# data=np.random.normal(size=1000,loc=0,scale=1)
# plt.boxplot(data,sym='o')
# plt.show()
##############四组箱线图
# np.random.seed(100)
# data=np.random.normal(size=(1000,4),loc=0,scale=1)
# labels=['A','B','C','D']
# plt.boxplot(data,sym='o',labels=labels)
# plt.show()
########################同时生成两张图
# fig1=plt.figure()
# ax1=fig1.add_subplot(111)
# ax1.plot([1,2,3],[3,2,1])
# fig2=plt.figure()
# ax2=fig2.add_subplot(111)
# ax2.plot([1,2,3],[1,2,3])
# plt.show()
###########################
x=np.arange(1,11,1)
y=x*x
plt.plot(x,x*2,label='Normal')
plt.plot(x,x*3,label='Fast')
plt.plot(x,x*4,label='Faster')
plt.legend(loc=3,ncol=2) #图例
plt.show()
网友评论