0

Problem : I want my seaborn boxplot to show names of pd.Series(Group A, Group B) on X axis, but it only shows number. The number 0 for the first pd.Series, and 1 for the next pd.Series object.

My codes are as follows.

import pandas as pd
import seaborn as sns

Group_A=pd.Series([26,21,22,26,19,22,26,25,24,21,23,23,18,29,22])
Group_B=pd.Series([18,23,21,20,20,29,20,16,20,26,21,25,17,18,19])

sns.set(style="whitegrid")
ax=sns.boxplot(data=[Group_A, Group_B], palette='Set2')

Result :

Please click here to see the image

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
Eiffelbear
  • 399
  • 1
  • 4
  • 23

1 Answers1

0

You can concatenate the two series into a dataframe. There are a lot of options to do so, here is one example which will produce nice names:

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

Group_A=pd.Series([26,21,22,26,19,22,26,25,24,21,23,23,18,29,22])
Group_B=pd.Series([18,23,21,20,20,29,20,16,20,26,21,25,17,18,19])
df = pd.DataFrame({"ColumnA" : Group_A, "ColumnB" : Group_B})

sns.set(style="whitegrid")
ax=sns.boxplot(data=df , palette='Set2')

plt.show()

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • I practice R exercises with Python and it takes much more lines to do the same thing on Python.. Thank you for your kind answer :D – Eiffelbear Sep 29 '18 at 13:58