How to change the order of x-axis labels in a seaborn lineplot? [duplicate] How to change the order of x-axis labels in a seaborn lineplot? [duplicate] python-3.x python-3.x

How to change the order of x-axis labels in a seaborn lineplot? [duplicate]


sort=False will do it.

As the seaborn doc states:

sort : boolean, optional

If True, the data will be sorted by the x and y variables, otherwise lines will connect points in the order they appear in the dataset.

The x variables are sorted in their "string-order":

'30s_RELAX_PULSE' < 'POST_RELAX_PULSE' < 'PRE_RELAX_PULSE'

which is not wanted.

The wanted behaviour is the aggregation by the x-values. This is done with the estimator='mean' (default). Every "Pulse Measure"(y) is grouped by the "Pulse Time" (x) and then the mean is calculated.

ax = sns.lineplot(x="Pulse Time", y="Pulse Measure", hue="Task",sort= False, data=df1_Relax_Pulse_Melted)

My Plot with other sample data:

correct order of the x variables