[英]Pandas scatter plot: multiple colors, and background
我正在尝试创建scores
的数据散点图,其中高于threshold
值的threshold
为红色。 我在使颜色相应地显示时遇到问题。 我还想为labels
指定的索引阴影图的背景,这是数据帧长度的0和1s的列表。 下面是我到目前为止的代码。 先谢谢您的帮助!
import pandas
...
values = pandas.DataFrame({"scores":scores, "labels":labels, "indices":range(len(labels))})
# plot alerts in red, others in black
alertValues = values.iloc[scores[scores >= threshold].index]
ax = alertValues.plot(kind="scatter", x="indices", y="scores", c='r',
marker='.', s=5, alpha=0.5)
values.plot(kind="scatter", x="indices", y="scores", c='r',
marker='.', s=5, alpha=0.5, ax=ax)
# show plot
plt.title(fileName)
plt.show()
问题是从熊猫DataFrame调用plot函数。 只将pyplot与列表一起使用会更好:
plt.figure()
plt.scatter(indices, scores)
plt.scatter(fooIndices, fooScores)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.