簡體   English   中英

Matplotlib散點圖標簽不區分點

[英]Matplotlib scatter plot label not distinguishing points

我試圖在散點圖中繪制一系列 IP 地址,然后根據它們為 0 或大於 0 的“檢測”標記它們。

盡管此圖確實生成了,但它為所有點着色相同,而不是通過惡意標簽將它們分開,非常感謝任何幫助!

df = pd.io.sql.read_sql('SELECT Date_scanned, IP, Detections FROM URLs', con=conn)
df['Date_scanned']=df['Date_scanned'].str.split(" ").str[0]
detections = df['Detections'].values

for row in df:
    for x in detections:
        if x > 0:
            malicious = "Yes"
        else:
            malicious = "No"

    plt.scatter(df['Date_scanned'], df['IP'], label=malicious)
plt.legend(loc='best')
plt.show()

您沒有告訴scatter()點應該是什么樣子,所以難怪您不會為每個案例得到不同的結果。

相反,您想要做的是在一次調用中繪制條件為“惡意”的所有點,並指定要使用的標記/顏色類型,然后對非惡意條件的第二次調用指定一個單獨的標記。

像這樣的東西:

df = pd.io.sql.read_sql('SELECT Date_scanned, IP, Detections FROM URLs', con=conn)
df['Date_scanned']=df['Date_scanned'].str.split(" ").str[0]

plt.scatter(df.loc[df.Detections>0,'Date_scanned'], df.loc[df.Detections>0,'IP'], marker='o', color='red', label="YES")
plt.scatter(df.loc[df.Detections≤0,'Date_scanned'], df.loc[df.Detections≤0,'IP'], marker='x', color='blue', label="NO")

plt.legend(loc='best')
plt.show()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM