数值位置不对
时间: 2024-02-28 08:56:43 浏览: 145
非常抱歉,代码有误,以下是正确的代码:
```python
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('data.csv')
sns.countplot(x='gender', hue='diabetes', data=df)
# 添加具体数值
for i in range(len(df['gender'].value_counts().index)):
for j in range(len(df['diabetes'].value_counts().index)):
plt.text(j + i*2 - 0.2,
df[(df['gender'] == df['gender'].value_counts().index[i]) & (df['diabetes'] == df['diabetes'].value_counts().index[j])]['gender'].count(),
df[(df['gender'] == df['gender'].value_counts().index[i]) & (df['diabetes'] == df['diabetes'].value_counts().index[j])]['gender'].count(),
ha='center')
plt.title('Gender vs Diabetes')
plt.show()
```
这样就会在带有分组的条形图上显示每个条形的具体数值。
阅读全文