与熊猫的seaborn tsplot问题

时间:2016-04-03 05:06:16

标签: python-3.x pandas seaborn

我正在尝试一些非常简单的事情,我确信这个错误是愚蠢的,所以请提前道歉。

以下是整个代码:

import pandas as pd
import numpy as np 
import seaborn as sns
import matplotlib.pyplot as plt

CrizWT = 134.2
CrizWT2 = 199.4

df = pd.DataFrame(columns = ('IC50', 'Cell line', 'Drug', 'Time point'))

df = df.append(pd.DataFrame([ [(4673/CrizWT), 'line 2', 'Criz', 1], \
                              [(919/CrizWT), 'line 2', 'Criz', 3], \
                              [(975.5/CrizWT), 'line 2', 'Criz', 7], \
                              [(164.2/CrizWT), 'line 2', 'Criz', 14], \
                              [(126.8/CrizWT), 'line 2', 'Criz', 21], \
                              [(2474/CrizWT), 'line 8', 'Criz', 1], \
                              [(565.8/CrizWT), 'line 8', 'Criz', 7], \
                              [(1368/CrizWT), 'line 8', 'Criz', 14], \
                              [(299.1/CrizWT), 'line 8', 'Criz', 21], \
                              [(395.5/CrizWT2), 'line 1', 'Criz', 1], \
                              [(2071/CrizWT2), 'line 1', 'Criz', 3], \
                              [(338.4/CrizWT2), 'line 1', 'Criz', 7], \
                              [(322.8/CrizWT2), 'line 1', 'Criz', 14], \
                              [(259.9/CrizWT2), 'line 1', 'Criz', 21], \
                              [(483.1/CrizWT2), 'line 3', 'Criz', 1], \
                              [(539.6/CrizWT2), 'line 3', 'Criz', 3], \
                              [(231.3/CrizWT2), 'line 3', 'Criz', 7], \
                              [(215.5/CrizWT2), 'line 3', 'Criz', 14], \
                              [(291.5/CrizWT2), 'line 3', 'Criz', 21]], \
                              columns = ('IC50', 'Cell line', 'Drug', 'Time point')))

print(df)
sns.tsplot(time = 'Time point', value = 'IC50', condition = 'Cell line', data = df)
plt.show()

当我打印数据帧时,它看起来很好:

         IC50 Cell line  Drug  Time point
0   34.821162    line 2  Criz           1
1    6.847988    line 2  Criz           3
2    7.269001    line 2  Criz           7
3    1.223547    line 2  Criz          14
4    0.944858    line 2  Criz          21
5   18.435171    line 8  Criz           1
6    4.216095    line 8  Criz           7
7   10.193741    line 8  Criz          14
8    2.228763    line 8  Criz          21
9    1.983450    line 1  Criz           1
10  10.386158    line 1  Criz           3
11   1.697091    line 1  Criz           7
12   1.618857    line 1  Criz          14
13   1.303410    line 1  Criz          21
14   2.422768    line 3  Criz           1
15   2.706118    line 3  Criz           3
16   1.159980    line 3  Criz           7
17   1.080742    line 3  Criz          14
18   1.461886    line 3  Criz          21

但是seaborn tsplot是空的! (轴标记正确,但没有图表。)

想法?

pandas / seaborn学习曲线继续。

1 个答案:

答案 0 :(得分:2)

我不是seaborn的专家,但我发现你的数据存在两个问题:

  1. 您在5个时间点对数据进行采样,但您的行中有19行 数据帧。缺少line 8 time point = 3的衡量标准

  2. Seaborn的tsplot旨在表现出不确定性,所以我相信你应该使用参数unit,而不是condition sns.tsplot()

  3. 一旦你纠正了这些问题,你将得到一个格式很好的情节如下:

    dx = pd.concat([df,
    pd.DataFrame({'IC50':10.386158,'Cell line':'line 8','Drug':'Criz','Time point':3.0}, index=[19])], axis=0)
    sns.tsplot(data = dx, time = 'Time point', value = 'IC50', unit="Cell line");
    

    enter image description here