dalekchef dalekchef - 6 months ago 49
Python Question

Seaborn tsplot subset of conditions

I have some data that I am plotting with seaborn using tsplot which looks fine.

I currently have 8 different categories possible for my "condition" input specified by a field "car_type" and I am wondering if I can use seaborn to call tsplot to only show a subset of these categories.

So I am hoping I can have one CSV with data for each "condition" but create a plot using seaborn to only show a tsplot of A,B,C or B,C instead of showing all possible categories A,B,C,D,E,F,G,H

I know I could create multiple CSV for each comparison, but I am hoping that I can specify condition="[car_type=A, car_type=B]" or something like that.

Answer

You do not have to create another dataset, but rather only query the element you'd want to focus on as shown:

import seaborn as sns
%matplotlib inline
import matplotlib.pyplot as plt

gammas = sns.load_dataset("gammas")    # Loading the gamma dataset
IPS = gammas.query("ROI == 'IPS'")     # Selecting subset of rows of ROI category 
AG = gammas.query("ROI == 'AG'")

f, ax = plt.subplots(ncols=2, sharey=True)

sns.tsplot(data=IPS, time="timepoint", unit="subject",
           condition="ROI", value="BOLD signal", ci=[68, 95], ax=ax[0])

sns.tsplot(data=AG, time="timepoint", unit="subject",
           condition="ROI", value="BOLD signal",ci=[68, 95], ax=ax[1])
Comments