【PY从0到1】数据可视化2
# tushare ID: 409200 # 数据可视化2 # 导入库 import numpy as np import seaborn as sns import matplotlib.pyplot as plt #设置美化参数 sns.set() # 1>可视化(绘制的数据在多个DataFrame中) # 准备画布 plt.figure(figsize=(8,6)) # 重置画布 # 生成数据画图 plt.plot([1,2,3,4], [2,4,6,8], 'b--', lw = 1.0, label = 'Line') # lw是线宽 # 对其中的参数进行调整 plt.ylabel('Y Numbers') plt.xlabel('X Numbers') plt.title('Number') plt.legend() # 绘制label标签 plt.ylim(0,10) # Y轴取值范围 # 2> 一次性绘制多条曲线 plt.figure(figsize=(8,6)) # 重置画布 a = np.arange(0,5,0.5) plt.plot(a,a,'r--', a,a**2,'g .', a,a**3,'b-',) # 3> 调整图像大小及坐标 plt.figure(figsize=(8,6)) # 调整大小(重置画布) np.random.seed(10) y = np.random.standard_normal(20) x = range(len(y)) plt.plot(x,y.cumsum()) # 画出y的累计和 # 4> 使两次绘图生成在一张图里 plt.figure(figsize=(8,6)) #重置画布 x1 = [1,3,5] y1 = [2,4,6] x2 = [2,4,6] y2 = [1,3,5] plt.plot(x1,y1,'b--',lw=1,label='line1') #这里的label是图例; plt.plot(x2,y2,'r*',lw=1,label='line2') plt.title('Two Line Plot') plt.ylabel('Y axis') plt.xlabel('X axis') plt.legend() plt.grid(True) # 网格开关 # 5> 二维列表绘制 plt.figure(figsize=(10,6)) #重置画布 np.random.seed(100) y = np.random.randn(100,2).cumsum(axis=0) # 按列累加 plt.plot(y,lw=1.0) plt.xlabel('Index') plt.ylabel('Value') plt.title('2 dimensions Plot') plt.grid(True) # 6> 子图绘制 plt.figure(figsize=(15,8)) plt.subplot(211) # 2*1张图的第一张图 plt.plot(y[:,0],'r--',lw=1.0, label='1') plt.ylabel('Value') plt.title('Sub Plot') plt.legend(loc=1) # 一般不需要传入参数 plt.subplot(212) # 2*1张图的第二张图 plt.plot(y[:,1],'m',lw=1.0,label='2') plt.xlabel('Index') plt.ylabel('Value') plt.legend(loc=0)
AI量化的成长之路

浙公网安备 33010602011771号