繁体   English   中英

熊猫散点图:多种颜色和背景

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM