Seaborn draw line on mean data points when plotting (not a linear line)

Viewed 1007

I'm trying to make my plots in Python better. I have created a Seaborn graph with the following code:

df = pd.DataFrame(dict(times=times, wait=wait, triage=triage))

flatui = ["#3498db", "#2ecc71", "#3498db"]
sns.set_palette(flatui)
sns.lmplot('times', 'wait', data=df, fit_reg=False, height=10, x_estimator=np.mean, truncate=True)
plt.ylabel("Waiting time",fontsize='20')
plt.xlabel("Time at day (0-23)",fontsize='20')

Using x_estimator = np.mean 2200+ data points are drawn. With the np.mean, only 24 points are drawn as x axis is time at day (0-23).

When using the np.mean I also want to draw a line through every point, is there a way to do this?

The plot the code produces looks like this:

enter image description here

1 Answers

You can additionally just plot the mean values using matplotlib. Assuming you have the 24 mean values in a list/array called mean_val, you can do the following. It will simply put a line connecting the mean values (circles).

ax = sns.lmplot('times', 'wait', data=df, fit_reg=False, height=10, x_estimator=np.mean, truncate=True)
ax.plot(range(len(mean_val)), mean_val, '-b') 
Related