Python金融数据可视化汇总
Python  /  管理员 发布于 7年前   183
通过本篇内容给大家介绍一下Python实现金融数据可视化中两列数据的提取、分别画、双坐标轴、双图、两种不同的图等代码写法和思路总结。
import matplotlib as mplimport numpy as npimport matplotlib.pyplot as pltnp.random.seed(2000)y = np.random.standard_normal((20,2))# print(y)'''不同的求和print(y.cumsum())print(y.sum(axis=0))print(y.cumsum(axis=0))'''# 绘图plt.figure(figsize=(7,4))plt.plot(y.cumsum(axis=0),linewidth=2.5)plt.plot(y.cumsum(axis=0),'bo')plt.grid(True)plt.axis("tight")plt.xlabel('index')plt.ylabel('values')plt.title('a simple plot')plt.show()
2.下面分别提取两组数据,进行绘图。
import matplotlib as mplimport numpy as npimport matplotlib.pyplot as pltnp.random.seed(2000)date = np.random.standard_normal((20,2))y = date.cumsum(axis=0)print(y)# 重点下面两种情况的区别print(y[1]) # 取得是 第1行的数据 [-0.37003581 1.74900181]print(y[:,0]) # 取得是 第1列的数据 [ 1.73673761 -0.37003581 0.21302575 0.35026529 ...# 绘图plt.plot(y[:,0],lw=2.5,label="1st",color='blue')plt.plot(y[:,1],lw=2.5,label="2st",color='red')plt.plot(y,'ro')# 添加细节plt.title("A Simple Plot",size=20,color='red')plt.xlabel('Index',size=20)plt.ylabel('Values',size=20)# plt.axis('tight')plt.xlim(-1,21)plt.ylim(np.min(y)-1,np.max(y)+1)# 添加图例plt.legend(loc=0)plt.show()
3.双坐标轴。
import matplotlib as mplimport numpy as npimport matplotlib.pyplot as pltnp.random.seed(2000)date = np.random.standard_normal((20,2))y = date.cumsum(axis=0)y[:,0]=y[:,0]*100fig,ax1 = plt.subplots()plt.plot(y[:,0],'b',label="1st")plt.plot(y[:,0],'ro')plt.grid(True)plt.axis('tight')plt.xlabel("Index")plt.ylabel('Values of 1st')plt.title("This is double axis label")plt.legend(loc=0)ax2=ax1.twinx()plt.plot(y[:,1],'g',label="2st")plt.plot(y[:,1],'r*')plt.ylabel("Values of 2st")plt.legend(loc=0)plt.show()
4. 分为两个图绘画。
import matplotlib as mplimport numpy as npimport matplotlib.pyplot as pltnp.random.seed(2000)date = np.random.standard_normal((20,2))y = date.cumsum(axis=0)y[:,0]=y[:,0]*100plt.figure(figsize=(7,5)) # 确定图片大小plt.subplot(211) # 确定第一个图的位置 (行,列,第几个)两行一列第一个图plt.plot(y[:,0],'b',label="1st")plt.plot(y[:,0],'ro')plt.grid(True)plt.axis('tight')plt.xlabel("Index")plt.ylabel('Values of 1st')plt.title("This is double axis label")plt.legend(loc=0)plt.subplot(212) # 确定第一个图的位置plt.plot(y[:,1],'g',label="2st")plt.plot(y[:,1],'r*')plt.ylabel("Values of 2st")plt.legend(loc=0)plt.show()
5.在两个图层中绘制两种不同的图(直线图立方图)
import matplotlib as mplimport numpy as npimport matplotlib.pyplot as pltnp.random.seed(2000)date = np.random.standard_normal((20,2))y = date.cumsum(axis=0)y[:,0]=y[:,0]*100plt.figure(figsize=(7,5)) # 确定图片大小plt.subplot(121) # 确定第一个图的位置plt.plot(y[:,0],'b',label="1st")plt.plot(y[:,0],'ro')plt.grid(True)plt.axis('tight')plt.xlabel("Index")plt.ylabel('Values',size=20)plt.title("1st date set")plt.legend(loc=0)plt.subplot(122) # 确定第一个图的位置plt.bar(np.arange(len(y[:,1])),y[:,1],width = 0.5,color='g',label="2nd") # 直方图的画法plt.grid(True)plt.xlabel("Index")plt.title('2nd date set')plt.legend(loc=0)plt.show()
以上就是本次交给大家的Python制作金融数据等用到的图形化界面代码写法。
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号