Conditional marker for scatterplot Matplotlib

Publié le: 12 octobre 2024
sur la chaîne: Emrah KAYA
5
0

Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram:   / ky.emrah  

Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!Conditional marker for scatterplot Matplotlib

I am trying to plot x1 and x2 against each other, and if class == 1, then marker should be +, if class == 0, then the marker should just be a dot.
The file.csv is structured like this, the class column which is the conditional will only be either 1 or 0:



x1
x2
mark




1
2
0


9
4
1


0
5
1


2
6
0






x1
x2
mark




1
2
0


9
4
1


0
5
1


2
6
0





x1
x2
mark



x1
x2
mark

x1
x2
mark


1
2
0


9
4
1


0
5
1


2
6
0



1
2
0

1
2
0

9
4
1

9
4
1

0
5
1

0
5
1

2
6
0

2
6
0
Here's the code I have:
df = pd.read_csv('file.csv')
print(df)
x1 = df['x1'].to_numpy()
x2 = df['x2'].to_numpy()
mark = df['class'].to_numpy()

figure, ax = plt.subplots()

for i in range(0,80,1):
if mark[i] 0:
ax.plot(x1[i], color="red", marker='o')
else:
ax.plot(x1[i], color="blue", marker='x')

df = pd.read_csv('file.csv')
print(df)
x1 = df['x1'].to_numpy()
x2 = df['x2'].to_numpy()
mark = df['class'].to_numpy()

figure, ax = plt.subplots()

for i in range(0,80,1):
if mark[i] 0:
ax.plot(x1[i], color="red", marker='o')
else:
ax.plot(x1[i], color="blue", marker='x')

This is what the result SHOULD look like:




Tags: python,pandas,matplotlib,plot,matplotlibpyplotSource of the question:
https://stackoverflow.com/questions/7...

Question and source license information:
https://meta.stackexchange.com/help/l...
https://stackoverflow.com/


Sur cette page du site, vous pouvez voir la vidéo en ligne Conditional marker for scatterplot Matplotlib durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Emrah KAYA 12 octobre 2024, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 5 fois et il a aimé 0 téléspectateurs. Bon visionnage!