通过本篇内容给大家介绍一下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制作金融数据等用到的图形化界面代码写法。
标签:
Python,金融,数据,可视化
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“Python金融数据可视化汇总”评论...
更新动态
2025年10月24日
2025年10月24日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]





