sns.countplot(x='smoking_history', data=df) plt.title('Smoking History Distribution') plt.show()照上
时间: 2023-12-20 17:04:31 浏览: 64
数据集-吸烟数据集带标注
5星 · 资源好评率100%
要在条形图上显示每个条形的具体数值,可以添加以下代码:
```python
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('data.csv')
sns.countplot(x='smoking_history', data=df)
# 添加具体数值
for i in range(len(df['smoking_history'].value_counts().index)):
plt.text(i,
df['smoking_history'].value_counts()[i],
df['smoking_history'].value_counts()[i],
ha='center',
va='bottom')
plt.title('Smoking History Distribution')
plt.show()
```
这样就会在条形图上显示每个条形的具体数值。
阅读全文