1
私はこのようになり、データ再構築しようとしている:私はsns.tsplot
にそれを養うことができるように複数の時系列信号をsns.tsplotで使用するために再構成する方法は?
t trial signal value
0 0 0 y -1
1 0 1 y 0
2 0 2 y 1
3 1 0 y 0
4 1 1 y 1
5 1 2 y 2
6 2 0 y 1
7 2 1 y 2
8 2 2 y 3
9 3 0 y 2
10 3 1 y 3
11 3 2 y 4
12 4 0 y 3
13 4 1 y 4
14 4 2 y 5
:このような何かに
t y0 y1 y2
0 0 -1 0 1
1 1 0 1 2
2 2 1 2 3
3 3 2 3 4
4 4 3 4 5
を。
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
fig = plt.figure()
num_points = 5
# Create some dummy line signals and assemble a data frame
t = np.arange(num_points)
y0 = t - 1
y1 = t
y2 = t + 1
df = pd.DataFrame(np.vstack((t, y0, y1, y2)).transpose(), columns=['t', 'y0', 'y1', 'y2'])
print(df)
# Do some magic transformations
df = pd.melt(df, id_vars=['t'])
print(df)
# Plot the time-series data
sns.tsplot(time="t", value="value", unit="trial", condition="signal", data=df, ci=[68, 95])
plt.savefig("dummy.png")
plt.close()
私はラインのためにこれを達成するために願っています:
https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.tsplot.html http://pandas.pydata.org/pandas-docs/stable/reshaping.html
OMG、あなたはSO速いと答えました!これは機能しますが、より簡単な変換はありませんか?私はこれが非常に一般的な使用法でなければならないように感じる。 – tarabyte
私はここで '融解'は最良の選択だと思います。しかし、あなたは 'print df.set_index( 't')のようなものを' melt'の代わりに使用することができます。 '' reset_index(name = 'value')。rename(columns = {'level_1': 'variable'}) '、それはより複雑です。 – jezrael
これは任意の数の試行に比例していないようです – tarabyte