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()
修改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()
修改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()
关闭聚合
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()
不同类别数据绘制
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()
显示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()
使用虚线
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()
有多组重复测量数据时
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
当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()
修改颜色映射的规范化方式
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()
修改线条粗细
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()
以日期作为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第一小章节学完了,后面要开始其他章节的学习了