信息的可视化是数据分析中最重要任务之一。可视化可以作为探索过程的一部分,帮助识别异常值或所需的数据转换,或者为建模提供一些想法。另外,构建网络交互式可视化可能是最终目标。Python 有很多附加库可以用来制作静态或动态的可视化文件,主要的是 matplotlib
。
简明 matplotlib API 入门
matplotlib
是一个用于生成出版级质量图表的桌面绘图包。
matplotlib
已经产生了一些数据可视化的附加工具包,使用matplotlib
进行底层绘图1,seaborn
。
%matplotlib # in iPython
%matplotlib inline # in Jupyter
plt.plot()
fig = plt.figure()
ax1 = fig.add_subplot(2, 2, 1)
ax2 = fig.add_subplot(2, 2, 2)
ax3 = fig.add_subplot(2, 2, 3)
fig, axes = plt.subplots()
plt.savefig('figpath.svg') # 文件类型是从文件扩展名中推断出来的。
使用 pandas 和 seaborn 绘图
seaborn 是由 Michael Waskom创建的统计图形库,它简化了很多常用可视化类型的生成。
导入 seaborn 会修改默认的 matplotlib 配色方案和绘图样式,这会提高图表的可读性和美观性。即使你不使用 seaborn 的 API,你可能更喜欢导入 seaborn 来为通用 matplotlib 图表提供更好的视觉美观度。
sns.regplot('m1', 'unemp', data=trans_data)
TypeError: regplot() got multiple values for argument 'data'
sns.pairplot()
sns.factorplot()
AttributeError: module 'seaborn' has no attribute 'factorplot'
其他 Python 可视化工具
- Bokeh
- Plotly
可以在 web 浏览器中创建动态的、交互式图像。