可视化计算是数据分析的重要组成部分,特别是模块matplotlib。
最近新一代绘图模块plotly横空出世,在互动性上具有绝对的优势。但绘制一些简单的图像还是使用matplotlib比较方便。
2017年matplotlib2.0发布,提供了六种绘图风格供用户选择。
不同的集成环境可以将matplotlib的绘图风格增加到20多种。
这些方法可以直接运用到pandas的绘图语句中。
使用pandas数据分析模块内置的plot命令绘制图像,代码如下:
#coding=utf-8
'''
Created on 2020.09.29
'''
import matplotlib.pyplot as plt
import pandas as pd
def dr_xtyp(_dat):
#xtyp=['bmh','dark_background','fivethirtyeight','ggplot','grayscale','default']
for xss in plt.style.available:
plt.style.use(xss);print(xss)
_dat['Open'].plot()
_dat['Close'].plot()
_dat['High'].plot()
_dat['Low'].plot()
fss="tmp\\stk001_"+xss+"_pd.png";plt.savefig(fss)
plt.show()
# =======================
df = pd.read_csv('dat\\appl2014.csv',index_col=0,parse_dates=[0],encoding='gbk')
d30=df[:30]
dr_xtyp(d30)
运行结果:

在tmp目录下会产生各种不同风格的图像。