小编T. *_*ter的帖子

如何使用 .boxplot 函数修复 matplotlib 中 pyplot 中的“X 必须具有 2 个或更少维度”错误?

我想使用 python 中 matplotlib 中的 pyplot 创建一个带有 2 个箱线图的图形。

我正在使用鸢尾花数据集,该数据集提供了三种类型 150 朵花的花瓣长度:Setosa、Versicolor、Virginica。我想为 Setosa 的花瓣长度创建一个箱线图,为 Versicolor 的花瓣长度创建一个箱线图,所有这些都在同一个图上。

我的代码基于本教程:https://matplotlib.org/gallery/pyplots/boxplot_demo_pyplot.html#sphx-glr-gallery-pyplots-boxplot-demo-pyplot-py

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)

python matplotlib boxplot

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

boxplot ×1

matplotlib ×1

python ×1