【问题标题】:Plot conditional on value of a variable [duplicate]以变​​量值为条件的绘图[重复]
【发布时间】:2018-02-07 03:09:09
【问题描述】:

我正在尝试以变量的值为条件注释绘图:

for i, txt in enumerate(vectors.word):
     if vectors['count']>=50:
     plt.annotate(txt, (yframe.x[i], yframe.y[i]), fontsize=20)

但我得到一个 ValueError:

The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

知道我的条件语句有什么问题吗?

【问题讨论】:

    标签: pandas matplotlib series annotate


    【解决方案1】:

    假设vectors 是pandas.DataFrame,您可能需要这种模式:

    from i, v in enumerate(vectors.itertuples()):
        if v.count>=50:
            ...
            ... v.word ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-20
      • 2014-02-06
      • 2018-03-25
      • 2019-03-08
      • 1970-01-01
      • 1970-01-01
      • 2018-08-10
      • 2018-05-14
      相关资源
      最近更新 更多