3.3 Seaborn
Seaborn是基于matplotlib的图形可视化python包。它提供了一种高度交互式界面,便于用户能够做出各种有吸引力的统计图表。
Seaborn是在matplotlib的基础上进行了更高级的API封装,从而使得作图更加容易,在大多数情况下使用seaborn能做出很具有吸引力的图,而使用matplotlib就能制作具有更多特色的图。应该把Seaborn视 为matplotlib的补充,而不是替代物。
3.3.1 快速上手
3.3.1.1 模式设置
import seaborn as sns sns.set(style = 'darkgrid',context = 'talk',font = 'STKaiti')
style设置,修改主题风格,属性如下:
style | 效果 |
darkgrid | 黑色网格(默认) |
whitegrid | 白色网格 |
dark | 黑色背景 |
white | 白色背景 |
ticks | 四周有刻度线的白背景 |
context设置,修改大小,属性如下:
context | 效果 |
paper | 越来越大越来越粗 |
notebook(默认) | 越来越大越来越粗 |
talk | 越来越大越来越粗 |
poster | 越来越大越来越粗 |
3.3.1.2 线形图
import seaborn as sns import matplotlib.pyplot as plt import pandas as pd import numpy as np sns.set(style = 'dark',context = 'poster',font = 'STKaiti') # 设置样式 plt.figure(figsize = (9, 6)) x = np.linspace(0, 2 * np.pi, 20) y = np.sin(x) sns.lineplot(x = x, y = y, color = 'green', ls = '--') sns.lineplot(x = x, y = np.cos(x), color = 'red',ls = '-.')
3.3.2.2 线形图