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