【问题标题】:I was loading dataframe in df and need to plot stacked plot我在 df 中加载数据框,需要绘制堆叠图
【发布时间】:2020-07-15 05:49:27
【问题描述】:

这是我编写的代码,用于在 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: 无法使用灵活类型执行累加

【问题讨论】:

  • This question 提到了您报告的相同错误。可能对你有点帮助

标签: python dataframe stacked-area-chart


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    相关资源
    最近更新 更多