Python金融数据可视化汇总


Posted in Python onNovember 17, 2017

通过本篇内容给大家介绍一下Python实现金融数据可视化中两列数据的提取、分别画、双坐标轴、双图、两种不同的图等代码写法和思路总结。

import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt

np.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()

Python金融数据可视化汇总

2.下面分别提取两组数据,进行绘图。

import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt

np.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()

Python金融数据可视化汇总

Python金融数据可视化汇总

3.双坐标轴。

import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt

np.random.seed(2000)
date = np.random.standard_normal((20,2))
y = date.cumsum(axis=0)

y[:,0]=y[:,0]*100

fig,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()

Python金融数据可视化汇总

4. 分为两个图绘画。

import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt

np.random.seed(2000)
date = np.random.standard_normal((20,2))
y = date.cumsum(axis=0)

y[:,0]=y[:,0]*100

plt.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()

Python金融数据可视化汇总

5.在两个图层中绘制两种不同的图(直线图立方图)

import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt

np.random.seed(2000)
date = np.random.standard_normal((20,2))
y = date.cumsum(axis=0)

y[:,0]=y[:,0]*100

plt.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金融数据可视化汇总

以上就是本次交给大家的Python制作金融数据等用到的图形化界面代码写法。

Python 相关文章推荐
Python 代码性能优化技巧分享
Aug 07 Python
python 网络爬虫初级实现代码
Feb 27 Python
Python制作简易注册登录系统
Dec 15 Python
Python算术运算符实例详解
May 31 Python
用python实现百度翻译的示例代码
Mar 09 Python
python实现将读入的多维list转为一维list的方法
Jun 28 Python
Python闭包函数定义与用法分析
Jul 20 Python
在双python下设置python3为默认的方法
Oct 31 Python
python通过robert、sobel、Laplace算子实现图像边缘提取详解
Aug 21 Python
python Popen 获取输出,等待运行完成示例
Dec 30 Python
python词云库wordcloud的使用方法与实例详解
Feb 17 Python
python flappy bird小游戏分步实现流程
Feb 15 Python
详解Python中的Numpy、SciPy、MatPlotLib安装与配置
Nov 17 #Python
Python中super函数的用法
Nov 17 #Python
python使用正则表达式替换匹配成功的组
Nov 17 #Python
python定时利用QQ邮件发送天气预报的实例
Nov 17 #Python
详解python eval函数的妙用
Nov 16 #Python
Python算法之图的遍历
Nov 16 #Python
Python之Scrapy爬虫框架安装及使用详解
Nov 16 #Python
You might like
Terran剧情介绍
2020/03/14 星际争霸
用PHP发电子邮件
2006/10/09 PHP
PHP If Else(elsefi) 语句
2013/04/07 PHP
PHP文件上传判断file是否己选择上传文件的方法
2014/11/10 PHP
php与Mysql的一些简单的操作
2015/02/26 PHP
PHP中大于2038年时间戳的问题处理方案
2015/03/03 PHP
如何使用jQuery+PHP+MySQL来实现一个在线测试项目
2015/04/26 PHP
PHP数组游标实现对数组的各种操作详解
2016/01/26 PHP
thinkphp3.2.0 setInc方法 源码全面解析
2018/01/29 PHP
TP框架实现上传一张图片和批量上传图片的方法分析
2020/04/23 PHP
tp5.1框架数据库子查询操作实例分析
2020/05/26 PHP
Javascript 个人笔记(没有整理,很乱)
2007/07/07 Javascript
使用JS进行目录上传(相当于批量上传)
2010/12/05 Javascript
JavaScript淡入淡出渐变简单实例
2015/08/06 Javascript
angular或者js怎么确定选中ul中的哪几个li
2017/08/16 Javascript
vue 设置proxyTable参数进行代理跨域
2018/04/09 Javascript
vue基于better-scroll实现左右联动滑动页面
2020/06/30 Javascript
vue@cli3项目模板怎么使用public目录下的静态文件
2020/07/07 Javascript
vue表单验证之禁止input输入框输入空格
2020/12/03 Vue.js
three.js 实现露珠滴落动画效果的示例代码
2021/03/01 Javascript
[02:16]完美世界DOTA2联赛PWL S3 集锦第三期
2020/12/21 DOTA
详解python中的Turtle函数库
2018/11/19 Python
Python基于内置函数type创建新类型
2020/10/22 Python
用css3制作纸张效果(外翻卷角)
2013/02/01 HTML / CSS
荷兰演唱会和体育比赛订票网站:viagogo荷兰
2018/04/08 全球购物
上海雨人软件技术开发有限公司测试题
2015/07/14 面试题
一名女生的自荐信
2013/12/08 职场文书
《鞋匠的儿子》教学反思
2014/03/02 职场文书
十八届三中全会感言
2014/03/10 职场文书
寒假家长评语大全
2014/04/16 职场文书
镇政府副镇长群众路线专题民主生活会对照检查材料
2014/09/19 职场文书
学生自我评语
2015/01/04 职场文书
2015年售后服务工作总结
2015/04/25 职场文书
房地产项目合作意向书
2015/05/08 职场文书
公司要求试用期员工提交“述职报告”,该怎么写?
2019/07/17 职场文书
浅谈MySQL函数
2021/10/05 MySQL