1

I am trying to plot the score of 100 students that passed two exams. The X value is the First Exam Score and the Y value is the Second Exam Score. I have a third column in my dataframe that is either 0 or 1. If they got admitted to the university with the score they got in the two exams, it is indicated with a 1 in my third column. If they did not get admitted, there is a 0.

I am trying to plot dots when they did not get admitted, and '+' when they got admitted.

How do I do this?

This is the code I have right now:

data.plot(kind='scatter', x='First Exam Score', y='Second Exam Score', figsize=(12,8))

This is the graph I have right now:

https://imgur.com/a/zOSzFdG

I want some points to be dots and some others to be '+', depending on the value they have in the third column

1
  • Is it a pandas dataframe? Is so, you might add the pandas tag. Also, you might want to add a sample of your dataframe (10 - 20 row are enough) so that people can better understand the question and try to help you. Add it as text, not as image. Commented Sep 26, 2019 at 18:36

1 Answer 1

4

You can do plot the selected data into the same axis:

data = pd.DataFrame({'First': np.random.randint(30,100, 100),
                     'Second': np.random.randint(30,100,100),
                     'Admitted': np.random.randint(0,2,100)})

fig, ax = plt.subplots()
markers = ['x','o']

for i in range(2):
    data[data['Admitted'].eq(i)].plot.scatter(x='First', 
                                              y='Second', 
                                              marker=markers[i],
                                              ax=ax)

Output:

enter image description here

Or you can use seaborn scatterplot with style:

enter image description here

But in my opinion, a better way is to color code with seaborn:

sns.scatterplot(data=data, x='First', y='Second', hue='Admitted', style='Admitted')

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.