导语:数据分析能力是一项非常重要的能力,尤其是在分析股票数据时,挖掘其中的有用信
息是成功的必要因素。而数据可视化可谓是秀数据分析能力的最好方式,本章内容主要介绍
python 的matplotlib 模块,让你的数据分析结果,show 出来!
matplotlib 绘图
开始之前,还是学习一个模块导入操作
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
让我们先搬上小白板
fig = plt.figure()
axes = fig.add_axes([0.2, 0.2, 1, 1]) # 左侧间距,底部间距,宽度,高度 (从 0 到1)
axes
----------------------- Page 134-----------------------
先画个 y=x2 曲线:
x = np.linspace(-10, 10)
y = x ** 2
axes.plot(x, y, 'r')
axes.set_xlabel('x') #设置X 轴
axes.set_ylabel('y') #设置Y 轴
axes.set_title('微笑') #设置标题
小白板上再插入一个小白板
axes2 = fig.add_axes([0.5, 0.5, 0.3, 0.3]) #插入面板2
axes2.plot(x, y, 'y')
axes2.set_xlabel('x')
axes2.set_ylabel('y')
axes2.set_title('微笑中微笑')
----------------------- Page 135-----------------------
plt.figure() 函数内部有figsize 和 dpi 参数,用于设置图像的大小和精度。
我们将上述代码中fig = plt.figure()改成fig = plt.figure(figsize=(8,4), dpi=100),结果如下:
----------------------- Page 136-----------------------
让我们尝试画一个沪深300 指数收盘价走势图:
x1_list=get_price('000300.SH', None, '20180125', '1d', ['close'], False, 'pre', 100, is_panel=1)
['close']
fig = plt.figure()
axes = fig.add_axes([0.1, 0.1, 2, 2]) #插入面板2
y=np.array(x1_list)
x=np.array(range(0,len(x1_list)))
axes.plot(x, y, 'r')
axes.set_xlabel(' 日期')
axes.set_ylabel('沪深300 指数值')
axes.set_title('沪深300 近10 日走势图')
----------------------- Page 137-----------------------
同时在小白板上绘制沪深300 指数和创业板指数 (净值数据)
fig =
息是成功的必要因素。而数据可视化可谓是秀数据分析能力的最好方式,本章内容主要介绍
python 的matplotlib 模块,让你的数据分析结果,show 出来!
matplotlib 绘图
开始之前,还是学习一个模块导入操作
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
让我们先搬上小白板
fig = plt.figure()
axes = fig.add_axes([0.2, 0.2, 1, 1]) # 左侧间距,底部间距,宽度,高度 (从 0 到1)
axes
----------------------- Page 134-----------------------
先画个 y=x2 曲线:
x = np.linspace(-10, 10)
y = x ** 2
axes.plot(x, y, 'r')
axes.set_xlabel('x') #设置X 轴
axes.set_ylabel('y') #设置Y 轴
axes.set_title('微笑') #设置标题
小白板上再插入一个小白板
axes2 = fig.add_axes([0.5, 0.5, 0.3, 0.3]) #插入面板2
axes2.plot(x, y, 'y')
axes2.set_xlabel('x')
axes2.set_ylabel('y')
axes2.set_title('微笑中微笑')
----------------------- Page 135-----------------------
plt.figure() 函数内部有figsize 和 dpi 参数,用于设置图像的大小和精度。
我们将上述代码中fig = plt.figure()改成fig = plt.figure(figsize=(8,4), dpi=100),结果如下:
----------------------- Page 136-----------------------
让我们尝试画一个沪深300 指数收盘价走势图:
x1_list=get_price('000300.SH', None, '20180125', '1d', ['close'], False, 'pre', 100, is_panel=1)
['close']
fig = plt.figure()
axes = fig.add_axes([0.1, 0.1, 2, 2]) #插入面板2
y=np.array(x1_list)
x=np.array(range(0,len(x1_list)))
axes.plot(x, y, 'r')
axes.set_xlabel(' 日期')
axes.set_ylabel('沪深300 指数值')
axes.set_title('沪深300 近10 日走势图')
----------------------- Page 137-----------------------
同时在小白板上绘制沪深300 指数和创业板指数 (净值数据)
fig =