我在df中加载数据帧,需要绘制堆叠图



这是我写的代码,用于在df中加载数据帧iris并绘制堆叠区域图

import matplotlib.pyplot as plt
import seaborn as sns
def read_dataset():
df = sns.load_dataset('iris')
print(df)
return df
def line_plot():
df = read_dataset()
col1 = "sepal_length"
col2 = "sepal_width"
col3 = "species"
plt.stackplot(col1, col2)
plt.show()
line_plot()

错误如下:

TypeError:无法使用灵活类型的执行累积

您似乎只犯了一个简单的错误。您没有正确设置变量col1、col2和col3。

col1 = df["sepal_length"]
col2 = df["sepal_width"]
col3 = df["species"]

最新更新