Pandas 散点图:多种颜色和背景
Pandas scatter plot: multiple colors, and background
我正在尝试创建 scores
中数据的散点图,其中 threshold
上方的值显示为红色。我在让颜色相应显示方面遇到问题。我还想为 labels
中指定的索引添加图形背景阴影,这是数据帧长度的 0 和 1 列表。下面是我到目前为止的代码。在此先感谢您的帮助!
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()
问题在于从 pandas DataFrame 调用绘图函数。将 pyplot 与列表一起使用会更好:
plt.figure()
plt.scatter(indices, scores)
plt.scatter(fooIndices, fooScores)
plt.show()
我正在尝试创建 scores
中数据的散点图,其中 threshold
上方的值显示为红色。我在让颜色相应显示方面遇到问题。我还想为 labels
中指定的索引添加图形背景阴影,这是数据帧长度的 0 和 1 列表。下面是我到目前为止的代码。在此先感谢您的帮助!
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()
问题在于从 pandas DataFrame 调用绘图函数。将 pyplot 与列表一起使用会更好:
plt.figure()
plt.scatter(indices, scores)
plt.scatter(fooIndices, fooScores)
plt.show()