Skip to content Skip to sidebar Skip to footer

How Do I Sort My X-axis By Ascending Month Order?

So I have a dataframe with the indices as datetime objects. I have created a new column to indicate which month each 'ride' in the dataframe is in: import numpy as np import date

Solution 1:

The x-coordinates must be numeric. When you supply an array of strings, Seaborn automatically sort it alphabetically. What you want can be achieved with sort=False (the default is True):

# True or omitted
sns.lineplot(x='month', y='distance', data=df1, sort=True)

Sort = True

# Set to False to keep the original order in your DataFrame
sns.lineplot(x='month', y='distance', data=df1, sort=False)

Sort = False

Post a Comment for "How Do I Sort My X-axis By Ascending Month Order?"