countplot got multiple values
时间: 2023-09-09 16:07:24 浏览: 152
三菱触摸屏GOT2000应用篇学习资料
Yes, you can use the `hue` parameter in `sns.countplot()` to plot multiple values. The `hue` parameter allows you to specify a categorical variable to group the data by and plot each group separately in a different color.
Here's an example:
```python
import seaborn as sns
import pandas as pd
# Create a sample dataset
data = {'gender': ['Male', 'Female', 'Male', 'Male', 'Female', 'Female', 'Male', 'Female', 'Female'],
'age_group': ['18-24', '25-34', '35-44', '18-24', '25-34', '35-44', '25-34', '18-24', '35-44']}
df = pd.DataFrame(data)
# Plot a countplot with hue
sns.countplot(data=df, x='gender', hue='age_group')
```
This will create a countplot with two bars for each gender (Male and Female), and each bar will be divided into three sections based on the age group (18-24, 25-34, and 35-44). You can customize the colors of each section using the `palette` parameter.
阅读全文