matplotlib
是 python 的绘图工具,这篇笔记记录了 matplotlib
库的使用。seaborn
库是以 matplotlib
库为基础的更高阶库,绘出的图也更加美观。使用 seaborn
库首先要导入。
import seaborn as sns
sns.set()
方法即可美化 matplotlib
画出的图形。美化的图形从白底变为了灰底,并且有网格,在图形颜色和字体等方面也有美化,例如。
sns.set()
x = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
y = [3, 4, 6, 8, 9, 10, 9, 11, 7, 8]
plt.plot(x, y)
set()
方法中还有一些参数可以设置。context
控制画的大小,可选值由大到小有 paper
、 notebook
、talk
、poster
。style
控制着样式,可选值有darkgrid
、whitegrid
、dark
、white
、ticks
。palette
为预设调色板,可选值有deep
、muted
、bright
、pastel
、dark
、colorblind
。font
用于设置字体,font_scale
用于设置字体大小,color_codes
使用颜色字母缩写表示颜色。
seaborn
绘图分为关联图、类别图、分布图、回归图、矩阵图、组合图六大类别。
seaborn
API 分为 Figure-level 和 Axes-level 两种,前者适合于快速绘图,后者与 matplotlib
更接近,绘图更加灵活。