How to set multiple tags using tsplot?

I have time series data in a pandas DataFrame and I would like to have separate markers for the rows. So far, I have managed to use the same marker for both lines using an argument marker='o'.

I use the example from http://stanford.edu/~mwaskom/software/seaborn/tutorial/timeseries_plots.html#specifying-input-data-with-long-form-dataframes , and I copied my copied and pasted code below.

How can I build separate markers for each line?

import numpy as np
np.random.seed(9221999)
import pandas as pd
from scipy import stats
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(palette="Set2")


def gamma_pdf(x, shape, coef, obs_err_sd=.1, tp_err_sd=.001):
    y = stats.gamma(shape).pdf(x) * coef
    y += np.random.normal(0, obs_err_sd, 1)
    y += np.random.normal(0, tp_err_sd, len(x))
    return y

gammas = []
n_units = 20
params = [(5, 1), (8, -.5)]
x = np.linspace(0, 15, 31)
for s in range(n_units):
    for p, (shape, coef) in enumerate(params):
        y = gamma_pdf(x, shape, coef)
        gammas.append(pd.DataFrame(dict(condition=[["pos", "neg"][p]] * len(x),
                                        subj=["subj%d" % s] * len(x),
                                        time=x * 2,
                                        BOLD=y), dtype=np.float))
gammas = pd.concat(gammas)

sns.tsplot(gammas, time="time", unit="subj",
           condition="condition", value="BOLD", marker="o")
plt.show()

Code output

+4
source share
1 answer

tsplot condition, , -hoc- :

ax = sns.tsplot(gammas, time="time", unit="subj",
                condition="condition", value="BOLD", marker="o")
ax.lines[-1].set_marker("s")
+3

All Articles