简体   繁体   English

根据条件在python plot中标记一个点

[英]Mark a point in python plot based on condition

I have the dataset df4:我有数据集 df4:

     Cumulexr   Cumulcoun  SignB
1  43.035714   24.603175    Yes
3  71.785714   50.513539    No
0  89.107143   75.241208    No
2  100.000000  100.000000   No

And I am plotting them as: plt.plot(df4["Cumulcoun"], df4["Cumulexr"], label="4 Cl.").我将它们绘制为: plt.plot(df4["Cumulcoun"], df4["Cumulexr"], label="4 Cl."). But I want additionally to mark the point(with a dot) that has SignB=Yes.但我还想标记具有 SignB=Yes 的点(用点)。 Any idea?任何的想法?

IIUC, you can create another dataframe with rows from df4 which have SignB = Yes . IIUC,您可以使用df4中具有SignB = Yes的行创建另一个 dataframe 。

import matplotlib.pyplot as plt 
import pandas as pd

X = [43.035, 71.785, 89.107, 100.000]
Y = [24.603, 50.513, 75.241, 100.000]
Sign = ["Yes", 'No', 'No', 'No']

df4 = pd.DataFrame({"Cumulexr": X, "Cumulcoun": Y, "SignB": Sign})
df1 = df4.loc[df4["SignB"] == 'Yes']

plt.plot(df4["Cumulcoun"], df4["Cumulexr"])
plt.plot(df1["Cumulcoun"], df1["Cumulexr"], marker='*')

plt.show()

This gives:这给出: 在此处输入图像描述

You can set marker='o' to get SignB = Yes data points as circles/points.您可以设置marker='o'以获得SignB = Yes数据点作为圆/点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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