Skip to content
Advertisement

X-axis out of order seaborn histplot

I am trying to create a seaborn histplot and am almost done, however, I noticed that my x-axis is out of order.

JavaScript

Displays: enter image description here

Adding order argument as shown here creates the following error(s):

JavaScript

How can I force that order on my x-axis?

Advertisement

Answer

You could create a bar plot, using np.histogram to count how many values are in each bin. The bins need to be set explicitly, as they aren’t equally spaced.

Using sns.histplot directly on the costs array would show bars with all different widths, which looks quite confusing. Also note that you can’t show a kde when the x-axis isn’t numeric.

JavaScript

example plot

Alternatively, sns.histplot() could be displayed with a logarithmic x-axis to make the bar widths more equal while maintaining a numeric axis. In that case a kde could be calculated on the logs of the values.

JavaScript

plot with logarithmic x-axis

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement