Iris 数据集可视化:柱状图和箱线图
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import warnings
warnings.filterwarnings('ignore')
from sklearn.datasets import load_iris
import seaborn as sns
步骤 0:数据收集
data = load_iris() df = pd.DataFrame(data.data, columns=data.feature_names) df['target'] = data.target
4. 创建柱状图 (bar)
plt.figure(figsize=(10, 6)) sns.countplot(x='target', data=df, palette=['red', 'green', 'blue']) plt.title('Distribution of Target') plt.xlabel('Target') plt.ylabel('Count')
5. 绘制箱线图 (boxplot)
plt.figure(figsize=(8, 6)) sns.boxplot(x='target', y='petal length (cm)', data=df) plt.title('Box Plot of Petal Length by Target') plt.xlabel('Target') plt.ylabel('Petal Length (cm)')
plt.show()
原文地址: https://www.cveoy.top/t/topic/Rvn 著作权归作者所有。请勿转载和采集!