简体   繁体   中英

Seaborn PointPlot Category Ordering Issue

I have been trying to use pointplot in Seaborn and in general it does what I need and I'm very impressed with the functionality.

My use case is fairly standard:

sns.pointplot(x="Category_1", y="Parameter", hue="Category 2", data=df);

My issue is that the Category I use for the hue contains strings in the form:

"1 string1", "2 string2", "3 string3", etc....

This is by design so that I can get a particular order if I sort. However when I run the Seaborn function the order is different.

By what logic does Seaborn order this, and is there a way for forcing a desired order. If I do:

A = df.Category2.unique()
A.sort()

I get the list order that I want.

Ben

As explained in the tutorial , categorical plotting functions follow a set of rules to determine the order of plot elements:

  • If a sequence of categories is passed to the order parameter, that order is used.
  • If the variable is a pandas Categorical with an assigned category order, that order is used.
  • If the variable is numeric, the values are shown in sorted order
  • Otherwise, the values are shown in the order that they appear in the DataFrame.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM