0

I have a pandas data frame with multiple columns that contain dates and one column with labels (string).

I want to plot the labels on the y-axis and the corresponding dates on the x-axis for all the columns. When I plot one it looks ok but then when I start adding the other columns it overplots the new data points and misses up the x-axis ticks.

Anyone knows what is causing this?

Here is a sample

Code 2011 2012 2013 2014 2015 2016
A1 8/1/2011 7/20/2012 7/10/2013 6/28/2014 6/18/2015 6/6/2016
A2 8/1/2011 7/20/2012 7/10/2013 6/28/2014 6/18/2015 6/6/2016
A3 7/10/2013 6/29/2014 6/18/2015 6/6/2016
A4 7/10/2013 6/28/2014 6/18/2015 6/6/2016
df = pd.read_csv('dates.csv', parse_dates=['2011', '2012', '2013', '2014', '2015', '2016'])
fig, ax = plt.subplots(figsize=(10, 6))

sns.stripplot(pd.to_datetime(df['2012']), df['Code'], color = 'r')
sns.stripplot(pd.to_datetime(df['2013']), df['Code'], color = 'g')
sns.stripplot(pd.to_datetime(df['2014']), df['Code'], color = 'k')

plt.xticks(rotation='vertical')

1 Answer 1

1

Seaborn is stronger with long form data. So you should melt then plot:

ax = sns.stripplot(data=df.melt('Code', value_name='date', var_name='year'), 
                   x='date', y='Code', hue='year')

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.