|
| 1 | +import numpy as np |
| 2 | +import pandas as pd |
| 3 | +import matplotlib.pyplot as plt |
| 4 | +import seaborn as sns |
| 5 | +sns.set(style="darkgrid") |
| 6 | + |
| 7 | +# 3.1 示例 |
| 8 | +df = pd.DataFrame(dict(time=np.arange(500), value=np.random.randn(500).cumsum())) |
| 9 | +sns.relplot(x="time", y="value", kind="line", data=df) |
| 10 | + |
| 11 | +df = pd.DataFrame(np.random.randn(500, 2).cumsum(axis=0), columns=["x", "y"]) |
| 12 | +sns.relplot(x="x", y="y", sort=False, kind="line", data=df) |
| 13 | + |
| 14 | +# 3.2 示例 |
| 15 | +fmri = sns.load_dataset("fmri") |
| 16 | +print(fmri) |
| 17 | + |
| 18 | +sns.relplot(x="timepoint", y="signal", kind="line", data=fmri) |
| 19 | + |
| 20 | +sns.relplot(x="timepoint", y="signal", ci=None, kind="line", data=fmri) |
| 21 | + |
| 22 | +sns.relplot(x="timepoint", y="signal", kind="line", ci="sd", data=fmri) |
| 23 | + |
| 24 | +sns.relplot(x="timepoint", y="signal", estimator=None, kind="line", data=fmri) |
| 25 | + |
| 26 | +sns.relplot(x="timepoint", y="signal", hue="event", kind="line", data=fmri) |
| 27 | + |
| 28 | +sns.relplot(x="timepoint", y="signal", hue="region", style="event", kind="line", data=fmri) |
| 29 | + |
| 30 | +sns.relplot(x="timepoint", y="signal", hue="region", style="event", dashes=False, markers=True, kind="line", data=fmri) |
| 31 | + |
| 32 | +sns.relplot(x="timepoint", y="signal", hue="event", style="event", kind="line", data=fmri) |
| 33 | + |
| 34 | +sns.relplot(x="timepoint", y="signal", hue="region", units="subject", estimator=None, kind="line", data=fmri.query("event == 'stim'")) |
| 35 | + |
| 36 | +# 3.3 示例 |
| 37 | +dots = sns.load_dataset("dots").query("align == 'dots'") |
| 38 | +print(dots) |
| 39 | + |
| 40 | +sns.relplot(x="time", y="firing_rate", |
| 41 | + hue="coherence", style="choice", |
| 42 | + kind="line", data=dots) |
| 43 | + |
| 44 | +palette = sns.cubehelix_palette(n_colors=6) # 数据集中 coherence 变量有6个数值,所以 n_colors=6 |
| 45 | +sns.relplot(x="time", y="firing_rate", hue="coherence", style="choice", palette=palette, kind="line", data=dots) |
| 46 | + |
| 47 | +from matplotlib.colors import LogNorm |
| 48 | +sns.relplot(x="time", y="firing_rate", |
| 49 | + hue="coherence", style="choice", |
| 50 | + hue_norm=LogNorm(), |
| 51 | + kind="line", data=dots) |
| 52 | + |
| 53 | +sns.relplot(x="time", y="firing_rate", |
| 54 | + size="coherence", style="choice", |
| 55 | + kind="line", data=dots) |
| 56 | + |
| 57 | +sns.relplot(x="time", y="firing_rate", |
| 58 | + hue="coherence", size="choice", |
| 59 | + kind="line", data=dots) |
| 60 | + |
| 61 | +# 3.4 示例 |
| 62 | +df = pd.DataFrame(dict(time=pd.date_range("2017年1月1日", periods=500), |
| 63 | + value=np.random.randn(500).cumsum())) |
| 64 | +g = sns.relplot(x="time", y="value", kind="line", data=df) |
| 65 | + |
| 66 | +g.fig.autofmt_xdate() |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
0 commit comments