Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight specific points in matplotlib scatterplot

I have a CSV with 12 columns of data. I'm focusing on these 4 columns

Right now I've plotted "Pass def" and "Rush def". I want to be able to highlight specific points on the scatter plot. For example, I want to highlight 1995 DAL point on the plot and change that point to a color of yellow.

I've started with a for loop but I'm not sure where to go. Any help would be great.

Here is my code:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import csv
import random

df = pd.read_csv('teamdef.csv')

x = df["Pass Def."]
y = df["Rush Def."]
z = df["Season"]

points = []
for point in df["Season"]:
    if point == 2015.0:

    print(point)


plt.figure(figsize=(19,10))
plt.scatter(x,y,facecolors='black',alpha=.55, s=100)
plt.xlim(-.6,.55)
plt.ylim(-.4,.25)
plt.xlabel("Pass DVOA")
plt.ylabel("Rush DVOA")
plt.title("Pass v. Rush DVOA")
plot.show
like image 915
jhaywoo8 Avatar asked Jul 21 '16 19:07

jhaywoo8


People also ask

How do you highlight points in a scatter plot in Python?

We can again use scatter() function, but this time with the data from the subsetted dataframe df. We also specify the color we want, here we specify the color to be red. Now we have highlighted the select data points, in this case outliers, in red color on a scatter plot.

How do I select points in Matplotlib?

Interactively selecting data points with the lasso tool. This examples plots a scatter plot. You can then select a few points by drawing a lasso loop around the points on the graph. To draw, just click on the graph, hold, and drag it around the points you need to select.


1 Answers

You can layer multiple scatters, so the easiest way is probably

plt.scatter(x,y,facecolors='black',alpha=.55, s=100)
plt.scatter(x, 2015.0, color="yellow")
like image 191
story645 Avatar answered Sep 23 '22 16:09

story645