pandas 突出显示 matplotlib 散点图中的特定点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38512485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Highlight specific points in matplotlib scatterplot
提问by jhaywoo8
I have a CSV with 12 columns of data. I'm focusing on these 4 columns
我有一个包含 12 列数据的 CSV。我专注于这 4 列
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.
现在我已经绘制了“Pass def”和“Rush def”。我希望能够突出散点图上的特定点。例如,我想在图中突出显示 1995 DAL 点并将该点更改为黄色。
I've started with a for loop but I'm not sure where to go. Any help would be great.
我已经开始使用 for 循环,但我不知道该去哪里。任何帮助都会很棒。
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
回答by story645
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")
plt.scatter(x,y,facecolors='black',alpha=.55, s=100)
plt.scatter(x, 2015.0, color="yellow")