sns.countplot(x='gender', hue='diabetes', data=df) plt.title('Gender vs Diabetes') plt.show()照上
时间: 2023-09-12 07:06:33 浏览: 53
要在带有分组的条形图上显示每个条形的具体数值,可以添加以下代码:
```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())
plt.title('Gender vs Diabetes')
plt.show()
```
这样就会在带有分组的条形图上显示每个条形的具体数值。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![tgz](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)