cancerconnector
cancerconnector

Reputation: 1285

seaborn tsplot issue with pandas

I'm trying something very straightforward and i'm sure the error is silly, so apologies in advance.

Here is the entire code:

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()

when I print the dataframe it looks fine:

         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

but the seaborn tsplot is empty! (the axes are labeled correctly, but there are no plots).

thoughts?

the pandas/seaborn learning curve continues.

Upvotes: 2

Views: 1226

Answers (1)

Sergey Bushmanov
Sergey Bushmanov

Reputation: 25199

I'm not an expert in seaborn, but I see 2 problems with your data:

  1. you sample data at 5 points in time, but you have 19 rows in your dataframe. Measurement for line 8 at time point = 3 is missing

  2. Seaborn's tsplot is meant to display uncertainty, so I believe you should use parameter unit, not condition in your sns.tsplot().

Once you have corrected those problems, you'll have a nicely formatted plot as follows:

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

Upvotes: 2

Related Questions