Seaborn 学习笔记(1.2)

使用relplot绘制线图

import seaborn as sns
from matplotlib import pyplot as plt

sns.set_style('darkgrid')
fmri = sns.load_dataset("fmri")
sns.relplot(x="timepoint", y="signal", kind="line", data=fmri)
plt.show()

Seaborn 学习笔记(1.2)_第1张图片

修改ci参数为None

import seaborn as sns
from matplotlib import pyplot as plt

sns.set_style('darkgrid')
fmri = sns.load_dataset("fmri")
sns.relplot(x="timepoint", y="signal", kind="line", ci=None, data=fmri)
plt.show()

Seaborn 学习笔记(1.2)_第2张图片

 

修改ci参数为'sd'

import seaborn as sns
from matplotlib import pyplot as plt

sns.set_style('darkgrid')
fmri = sns.load_dataset("fmri")
sns.relplot(x="timepoint", y="signal", kind="line", ci="sd", data=fmri)
plt.show()

Seaborn 学习笔记(1.2)_第3张图片

关闭聚合

import seaborn as sns
from matplotlib import pyplot as plt

sns.set_style('darkgrid')
fmri = sns.load_dataset("fmri")
sns.relplot(x="timepoint", y="signal", estimator=None, kind="line", data=fmri)
plt.show()

Seaborn 学习笔记(1.2)_第4张图片

不同类别数据绘制

import seaborn as sns
from matplotlib import pyplot as plt

sns.set_style('darkgrid')
fmri = sns.load_dataset("fmri")
ax = sns.lineplot(x="timepoint", y="signal", hue="event", style="event", palette="ch:r=-.5,l=.75", data=fmri)
ax.legend(shadow=False, fancybox=False, ncol=1, fontsize=10, loc='upper right')
plt.show()

Seaborn 学习笔记(1.2)_第5张图片

显示marker

import seaborn as sns
from matplotlib import pyplot as plt

sns.set_style('darkgrid')
fmri = sns.load_dataset("fmri")
ax = sns.lineplot(x="timepoint", y="signal", hue="event", style="event", palette="ch:r=-.5,l=.75", markers=True, data=fmri)
ax.legend(shadow=False, fancybox=False, ncol=1, fontsize=10, loc='upper right')
plt.show()

Seaborn 学习笔记(1.2)_第6张图片

使用虚线

import seaborn as sns
from matplotlib import pyplot as plt

sns.set_style('darkgrid')
fmri = sns.load_dataset("fmri")
ax = sns.lineplot(x="timepoint", y="signal", hue="event", style="event", palette="ch:r=-.5,l=.75", dashes=False, markers=True, data=fmri)
ax.legend(shadow=False, fancybox=False, ncol=1, fontsize=10, loc='upper right')
plt.show()

Seaborn 学习笔记(1.2)_第7张图片

有多组重复测量数据时

import seaborn as sns
from matplotlib import pyplot as plt

sns.set_style('darkgrid')
fmri = sns.load_dataset("fmri")
ax = sns.lineplot(x="timepoint", y="signal", hue="region",estimator=None,
                  units="subject", style="event", palette="ch:r=-.5,l=.75", data=fmri.query("event == 'stim'"))
ax.legend(shadow=False, fancybox=False, ncol=1, fontsize=10, loc='upper right')
plt.show()

一定要设置estimator=None

Seaborn 学习笔记(1.2)_第8张图片

当hue为数字变量时
import seaborn as sns
from matplotlib import pyplot as plt

sns.set_style('darkgrid')
dots = sns.load_dataset("dots").query("align == 'dots'")
palette = sns.cubehelix_palette(light=.8, n_colors=6)
#print(palette)
ax = sns.lineplot(x="time", y="firing_rate", hue="coherence", style="choice",
                  palette=palette, data=dots)
ax.legend(shadow=False, fancybox=False, ncol=1, fontsize=10, loc='upper right')
plt.show()

Seaborn 学习笔记(1.2)_第9张图片

修改颜色映射的规范化方式

import seaborn as sns
from matplotlib import pyplot as plt
from matplotlib.colors import LogNorm

sns.set_style('darkgrid')
dots = sns.load_dataset("dots").query("align == 'dots'")
palette = sns.cubehelix_palette(light=.8, n_colors=6)
#print(palette)
ax = sns.lineplot(x="time", y="firing_rate", hue="coherence", hue_norm=LogNorm(), style="choice",
                  palette=palette, data=dots)
ax.legend(shadow=False, fancybox=False, ncol=1, fontsize=10, loc='upper right')
plt.show()

Seaborn 学习笔记(1.2)_第10张图片

修改线条粗细

import seaborn as sns
from matplotlib import pyplot as plt
from matplotlib.colors import LogNorm

sns.set_style('darkgrid')
dots = sns.load_dataset("dots").query("align == 'dots'")
palette = sns.cubehelix_palette(light=.8, n_colors=6)
#print(palette)
ax = sns.lineplot(x="time", y="firing_rate", hue="coherence", hue_norm=LogNorm(), size="coherence", style="choice",
                  palette=palette, data=dots)
ax.legend(shadow=False, fancybox=False, ncol=1, fontsize=10, loc='upper right')
plt.show()

Seaborn 学习笔记(1.2)_第11张图片

以日期作为x

import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#from matplotlib.colors import LogNorm

sns.set_style('darkgrid')
df = pd.DataFrame(dict(time=pd.date_range("2017-1-1", periods=500),
                       value=np.random.randn(500).cumsum()))
g = sns.relplot(x="time", y="value", kind="line", data=df)
g.fig.autofmt_xdate()
plt.show()

Seaborn 学习笔记(1.2)_第12张图片

终于把seaborn第一小章节学完了,后面要开始其他章节的学习了

你可能感兴趣的:(python,seaborn)