[英]How to increase space between values on x-axis of box plot?
I have the below code for a boxplot and as you can see all values along x-axis are not spaced.我有下面的箱线图代码,你可以看到沿 x 轴的所有值都没有间隔。 How can i adjust this?
我该如何调整这个?
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df=pd.read_excel("RBA_KYC_Accounts_ALL_Ids.xlsx")
sns.boxplot(x='profession', y='rbaValue', data=df, width=0.8, palette="PRGn")
Your 'profession' seems to be in floating point format.您的“专业”似乎是浮点格式。 You can change it to integer format via
.astype(int)
.您可以通过
.astype(int)
将其更改为 integer 格式。 With plt.subplots
you can also set a wider figsize
:使用
plt.subplots
您还可以设置更宽的figsize
:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.DataFrame({'profession': np.random.randint(1, 31, 200) * 1.0,
'rbaValue': np.random.binomial(100, 0.02, 200)})
df['profession'] = df['profession'].astype(int)
fig, ax = plt.subplots(figsize=(12, 3))
sns.boxplot(x='profession', y='rbaValue', data=df, width=0.8, palette="PRGn", ax=ax)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.