目录
-
安装:pip install seaborn
-
代码:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import seaborn as sns
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
# %matplotlib inline
def sinplot(flip=1):
x = np.linspace(0, 14, 100)
for i in range(1, 7):
plt.plot(x, np.sin(x + i * .5) * (7 - i) * flip)
sinplot()
sns.set()
sinplot()
5种主题风格
- darkgrid-深红
- whitegrid-白金
- dark
- white
- ticks
主题风格使用:
sns.set_style("whitegrid")
sinplot()
sns.boxplot(data )
sns.set_style("ticks")
data = np.random.normal(size=(20, 6)) + np.arange(6) / 2
sns.boxplot(data=data)
其中:
data =
[[-0.94195027 1.44870967 0.46634394 2.31950556 1.28164177 2.23166763]
[-1.42569844 1.26202434 0.36867356 2.61809288 1.84887242 3.62734384]
[ 0.29016515 1.7174145 0.34442658 1.40382427 1.04916117 3.52742832]
[-0.92631783 0.26799419 1.15770759 -0.00877127 3.27188841 3.07369347]
........]
随机数生成补充:
用despine()删除图表边框:
sinplot()
sns.despine()
sns.violinplot(数据)
data = np.random.normal(size=(20, 6)) + np.arange(6) / 2
print(data)
sns.violinplot(data)
sns.despine(offset=10) # offset指定图离轴线距离
画子图
with sns.axes_style("darkgrid"):
plt.subplot(211)
sinplot()
plt.subplot(212)
sinplot(-1)
sns.set_context(“纸”)
sns.set_context("paper", font_scale=1.5, rc={"lines.linewidth": 2.5})
'''可设置set_context参数(paper<talk<poster<?notebook)调整大小'''
plt.figure(figsize=(8, 6))
sinplot()
注:本学习笔记来自《唐宇迪python数据分析与机器学习实战》