我想使用 python 中 matplotlib 中的 pyplot 创建一个带有 2 个箱线图的图形。
我正在使用鸢尾花数据集,该数据集提供了三种类型 150 朵花的花瓣长度:Setosa、Versicolor、Virginica。我想为 Setosa 的花瓣长度创建一个箱线图,为 Versicolor 的花瓣长度创建一个箱线图,所有这些都在同一个图上。
import numpy as np
import pandas as pd
from sklearn.datasets import load_iris
from matplotlib import pyplot as plt
# From the iris dataset I create a dataframe which contains only the features
# of the flowers (sepal length, sepal width, petal length, petal width and the
# flower type.
data = load_iris()
X= data["data"]
y = data ["target"]
iris=pd.DataFrame(X)
iris["target"]=y
iris.columns=data['feature_names']+["target"]
iris["target"]=iris["target"].apply(lambda …Run Code Online (Sandbox Code Playgroud)