简体   繁体   English

Seaborn箱形图在x轴上显示数字,而不是pd.Series对象的名称

[英]Seaborn boxplot showing number on x-axis, not the name of pd.Series object

Problem : I want my seaborn boxplot to show names of pd.Series(Group A, Group B) on X axis, but it only shows number. 问题:我希望我的盒装箱图在X轴上显示pd.Series(Group A,Group B)的名称,但只显示数字。 The number 0 for the first pd.Series, and 1 for the next pd.Series object. 第一个pd.Series对象的数字为0,下一个pd.Series对象的数字为1。

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 : 结果:

请点击这里查看图片

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()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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