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 相关文章推荐
用pywin32实现windows模拟鼠标及键盘动作
Apr 22 Python
python网络编程学习笔记(10):webpy框架
Jun 09 Python
python实现简单温度转换的方法
Mar 13 Python
Python使用scrapy采集数据过程中放回下载过大页面的方法
Apr 08 Python
深入理解python try异常处理机制
Jun 01 Python
利用Python实现网络测试的脚本分享
May 26 Python
基于python3 类的属性、方法、封装、继承实例讲解
Sep 19 Python
python3+PyQt5实现自定义分数滑块部件
Apr 24 Python
python 获取一个值在某个区间的指定倍数的值方法
Nov 12 Python
pytorch加载语音类自定义数据集的方法教程
Nov 10 Python
python爬虫之利用selenium模块自动登录CSDN
Apr 22 Python
Python Django获取URL中的数据详解
Nov 01 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
使用Xdebug调试和优化PHP程序之[1]
2007/04/17 PHP
将php数组输出html表格的方法
2014/02/24 PHP
PHP生成自适应大小的缩略图类及使用方法分享
2014/05/06 PHP
php集成动态口令认证
2016/07/21 PHP
高效率JavaScript编写技巧整理
2013/08/23 Javascript
DOM基础教程之事件对象
2015/01/20 Javascript
JQuery复制DOM节点的方法
2015/06/11 Javascript
jQuery.extend 函数及用法详细
2015/09/06 Javascript
jQuery自定义图片缩放拖拽插件imageQ实现方法(附demo源码下载)
2016/05/27 Javascript
javascript容错处理代码(屏蔽js错误)
2017/01/20 Javascript
关于Ajax的原理以及代码封装详解
2017/09/08 Javascript
JavaScript实现计数器基础方法
2017/10/10 Javascript
详解vue-admin和后端(flask)分离结合的例子
2018/02/12 Javascript
vuejs简单验证码功能完整示例
2019/01/08 Javascript
Vue+Element UI+vue-quill-editor富文本编辑器及插入图片自定义
2019/08/20 Javascript
OpenLayers加载缩放控件使用方法详解
2020/09/25 Javascript
python检查字符串是否是正确ISBN的方法
2015/07/11 Python
Python基础语法(Python基础知识点)
2016/02/28 Python
asyncio 的 coroutine对象 与 Future对象使用指南
2016/09/11 Python
关于反爬虫的一些简单总结
2017/12/13 Python
python求最大值最小值方法总结
2019/06/25 Python
pytorch对梯度进行可视化进行梯度检查教程
2020/02/04 Python
python json.dumps中文乱码问题解决
2020/04/01 Python
专科毕业生自我鉴定
2013/12/01 职场文书
给小学生的新年寄语
2014/04/04 职场文书
爱我中华教学反思
2014/04/28 职场文书
教师节演讲稿
2014/05/06 职场文书
信用卡结清证明怎么写
2014/09/13 职场文书
2015年个人自我剖析材料
2014/12/29 职场文书
公司捐书倡议书
2015/04/27 职场文书
毕业论文致谢部分怎么写
2015/05/14 职场文书
2016圣诞节贺卡寄语
2015/12/07 职场文书
OpenCV-Python直方图均衡化实现图像去雾
2021/06/07 Python
Python实战之OpenCV实现猫脸检测
2021/06/26 Python
简单且有用的Python数据分析和机器学习代码
2021/07/02 Python
Win2008系统搭建DHCP服务器
2022/06/25 Servers