对红酒质量数据集5个可视化图表,python实现
时间: 2024-03-27 22:36:31 浏览: 206
葡萄酒质量评价问题数学建模-完整paper+源码
5星 · 资源好评率100%
好的,这里是对红酒质量数据集的5个可视化图表的Python实现代码:
1. 直方图:
```python
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('winequality-red.csv', sep=';')
plt.hist(data['quality'], bins=6, edgecolor='black')
plt.xlabel('Quality')
plt.ylabel('Count')
plt.title('Wine Quality Distribution')
plt.show()
```
2. 箱线图:
```python
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('winequality-red.csv', sep=';')
plt.boxplot(data['quality'])
plt.xlabel('Quality')
plt.title('Wine Quality Distribution')
plt.show()
```
3. 散点图矩阵:
```python
import pandas as pd
import matplotlib.pyplot as plt
from pandas.plotting import scatter_matrix
data = pd.read_csv('winequality-red.csv', sep=';')
scatter_matrix(data, figsize=(10,10))
plt.show()
```
4. 热力图:
```python
import pandas as pd
import seaborn as sns
data = pd.read_csv('winequality-red.csv', sep=';')
corr = data.corr()
sns.heatmap(corr, cmap='coolwarm', annot=True)
plt.show()
```
5. 折线图:
```python
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('winequality-red.csv', sep=';')
plt.plot(data['quality'], data['fixed acidity'], label='Fixed Acidity')
plt.plot(data['quality'], data['volatile acidity'], label='Volatile Acidity')
plt.plot(data['quality'], data['citric acid'], label='Citric Acid')
plt.plot(data['quality'], data['residual sugar'], label='Residual Sugar')
plt.xlabel('Quality')
plt.ylabel('Feature')
plt.title('Features vs Quality')
plt.legend()
plt.show()
```
阅读全文