import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"simhei.ttf", size=14)
data=pd.read_excel('moive.xlsx')
x = [5,3,31,59,60,80]
y = [100,95,105,2,3,10]
labels = ["《战狼》","《红海行动》","《碟中谍6》","《前任3》","《春娇与志明》","《泰坦尼克号》"]
plt.scatter(x,y,s=120)
plt.xlabel("亲吻次数",fontproperties=font)
plt.ylabel("打斗次数",fontproperties=font)
plt.xticks(range(0,150,10))
plt.yticks(range(0,150,10))
count = 0
for x_i,y_i in zip(x,y):
plt.annotate(f"{labels[count]}",xy=(x_i,y_i),xytext=(x_i,y_i),fontproperties=font)
count+=1
2.使用numpy计算欧式距离
data=pd.read_excel('moive.xlsx')
data
dis=np.sqrt((data['打斗次数']- data.loc[6,"打斗次数"])**2+(data['接吻次数']- data.loc[6,"接吻次数"])**2)
data['距离']=dis
data