Python金融数据可视化汇总

 更新时间:2017年11月17日 14:33:52   投稿:laozhang  
这篇文章主要介绍了Python金融数据可视化(两列数据的提取,分别画,双坐标轴,双图,两种不同的图)等内容。

通过本篇内容给大家介绍一下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()

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

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

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

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制作金融数据等用到的图形化界面代码写法。

相关文章

  • ubuntu上安装python的实例方法

    ubuntu上安装python的实例方法

    在本篇文章里小编给大家整理的是关于怎么在ubuntu安装python的相关方法,以后需要的朋友们可以学习下。
    2019-09-09
  • Python中判断语句入门指南(if elif else语句)

    Python中判断语句入门指南(if elif else语句)

    if elif else语句是Python中的控制语句,用于根据条件执行不同的操作,下面这篇文章主要给大家介绍了关于Python中判断语句入门指南(if elif else语句)的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2023-05-05
  • 简单介绍Python中用于求最小值的min()方法

    简单介绍Python中用于求最小值的min()方法

    这篇文章主要介绍了简单介绍Python中用于求最小值的min()方法,是Python入门中的基础知识,需要的朋友可以参考下
    2015-05-05
  • Python记录详细调用堆栈日志的方法

    Python记录详细调用堆栈日志的方法

    这篇文章主要介绍了Python记录详细调用堆栈日志的方法,涉及Python调用堆栈日志的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
    2015-05-05
  • Python中assert函数的使用(含源代码)

    Python中assert函数的使用(含源代码)

    本文主要介绍了Python中assert函数的使用(含源代码),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-04-04
  • Python实现GIF动图以及视频卡通化详解

    Python实现GIF动图以及视频卡通化详解

    本文主要介绍了如何使用Python中的animegan2-pytorch实现动图以及视频的卡通化效果,文中的代码具有一定的学习价值,需要的朋友可以参考一下
    2021-12-12
  • 跟老齐学Python之for循环语句

    跟老齐学Python之for循环语句

    看这个标题,有点匪夷所思吗?为什么for是难以想象的呢?因为在python中,它的确是很常用而且很强悍,强悍到以至于另外一个被称之为迭代的东西,在python中就有点相形见绌了。在别的语言中,for的地位从来没有如同python中这么高的。
    2014-10-10
  • python实现图片文件批量重命名

    python实现图片文件批量重命名

    这篇文章主要为大家详细介绍了python实现图片文件批量重命名,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-05-05
  • Python类的动态绑定实现原理

    Python类的动态绑定实现原理

    这篇文章主要介绍了Python类的动态绑定实现原理,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-03-03
  • python PyAUtoGUI库实现自动化控制鼠标键盘

    python PyAUtoGUI库实现自动化控制鼠标键盘

    这篇文章主要介绍了python PyAUtoGUI库实现自动化控制鼠标键盘,帮助大家更好的理解和使用python,感兴趣的朋友可以了解下
    2020-09-09

最新评论