tsplot out of bounds error in Python seaborn
Question: i'm trying to plot time series data as points in seaborn, colored by
condition. i tried the following:

    
    
    import matplotlib
    import matplotlib.pylab as plt
    import seaborn as sns
    import pandas
    
    df = pandas.DataFrame({"t": [0, 1],
                           "y": [1, 1],
                           "c": ["A", "B"]})
    colors = {"A": "r", "B": "g"}
    fig = plt.figure()
    # this fails
    sns.tsplot(time="t", value="y", condition="c", unit="c",
               data=df, err_style="unit_points", interpolate=False,
               color=colors)
    plt.show()
    

the error is:

    
    
    x_diff = x[1] - x[0]
    IndexError: index 1 is out of bounds for axis 0 with size 1
    

however if i plot the data as:

    
    
    # this works
    sns.pointplot(x="t", y="y", hue="c", join=False, data=df)
    

then it works. `pointplot` treats time as categorical data though which is not
right for this. how can this be done with `tsplot`? it should give the same
result as `pointplot` except the x-axis (`t`) should scale quantitatively like
time and not as categorical.

**update**

here's a revised example that shows `tsplot` fails even when there are
multiple observations for most of the labels. in this df 2 out of 3 conditions
have multiple observations, but 1 condition that doesn't is enough to cause
the error:

    
    
    df = pandas.DataFrame({"t": [0, 1.1, 2.9, 3.5, 4.5, 5.9],
                           "y": [1, 1, 1, 1, 1, 1],
                           "c": ["A", "A", "B", "B", "B", "C"]})
    colors = {"A": "r", "B": "g", "C": "k"}
    print df
    fig = plt.figure()
    # this works but time axis is wrong
    #sns.pointplot(x="t", y="y", hue="c", join=False, data=df)
    
    # this fails
    sns.tsplot(time="t", value="y", condition="c", unit="c",
               data=df, err_style="unit_points", interpolate=False,
               color=colors)
    plt.show()
    

@mwaskom suggested making ordinary plot. doing that manually is difficult is
error prone and duplicates work that seaborn already does. seaborn already has
a way to plot and facet data by various features in dataframes and i don't
want to reproduce this code. here's a way to do manually which is cumbersome:

    
    
    # solution using plt.subplot
    # cumbersome and error prone solution
    # the use of 'set' makes the order non-deterministic
    for l in set(df["c"]):
        subset = df[df["c"] == l] 
        plt.plot(subset["t"], subset["y"], "o", color=colors[l], label=l)
    

basically i am looking for something like `sns.pointplot` that uses numeric,
rather than categorical x-axis. does seaborn have something like this? another
way to think of it is as a dataframe aware version of `plt.scatter` or
`plt.plot`.


Answer: I think the problem really is that you have too few observations. 2
observations for 2 conditions means there will be only 1 observation for each
condition. For a time-series plot, this is probably not going to work. `x_diff
= x[1] - x[0]` calculates the time interval length and can't work with just
one observation per group.

If you have more than 1 observation per group, i.e.:

    
    
    df = pandas.DataFrame({"t": [0, 1, 2, 3],
                           "y": [1, 1, 2, 4],
                           "c": ["A", "B", "A", "B"]})
    

it should plot just fine.

