导包:
import matplotlib.pyplot as plt
import statsmodels.api as sm
import scipy.stats as stats
import pandas as pd
import tushare as ts
from pylab import *
曲线图:
sz=pd.read_excel("上证指数.xlsx")
sz_high=datasz["high"].values
sz_low=datasz["low"].values
x_high=[i for i in range(len(sz_high))]
x_low=[i for i in range(len(sz_low))]
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']
plt.rcParams['axes.unicode_minus'] = False
plt.xlabel('日期',fontsize=8)
plt.ylabel('价格',fontsize=8)
plt.plot(x_low,datasz_low,label='最高价',color="r")
plt.plot(x_high,datasz_high,label='最低价',color="y")
plt.title("上证指数最高价和最低价曲线图")
plt.legend()
直方图:
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']
plt.rcParams['axes.unicode_minus'] = False
sz=pd.read_excel("农业银行.xlsx")
sz_close=datasz["close"].values
x_close=[i for i in range(len(sz_close))]
plt.xlabel('日期',fontsize=8)
plt.ylabel('价格',fontsize=8)
plt.title("农业银行 2020 年收盘价的直方图")
plt.hist(sz_close, bins=40, facecolor="blue", edgecolor="black", alpha=0.6)
# 显示横轴标签
plt.xlabel("频率")
# 显示纵轴标签
plt.ylabel("收盘价")
# 显示图标题
plt.show()
plt.scatter(x_Yield_shangzheng,Yield_shangzheng, c="b", alpha=0.5,label='上证指数')
plt.scatter(x_Yield_nongye,Yield_nongye, c="y", alpha=0.5,label='农业银行')
plt.xlabel('时间日期',fontsize=8)
plt.ylabel('价格',fontsize=8)
plt.title("收益率由相关性散点图")
plt.legend()
plt.plot(x_Yield_shangzheng,Yield_shangzheng, c="b", alpha=0.5,label='上证指数')
plt.plot(x_Yield_nongye,Yield_nongye, c="y", alpha=0.5,label='农业银行')
plt.title("收益率曲线")
plt.legend()