帮我优化一下代码 import matplotlib.pyplot as plt
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
import pandas as pd
import tkinter as tk
from tkinter import filedialog
import csv
import numpy as np
filepath = filedialog.askopenfilename()
readData = pd.read_csv(filepath, encoding = 'gb2312') # 读取csv数据
print(readData)
xdata = readData.iloc[:, 2].tolist() # 获取dataFrame中的第3列,并将此转换为list
ydata = readData.iloc[:, 3].tolist() # 获取dataFrame中的第4列,并将此转换为list
Color_map = {
'0x0': 'r',
'0x10': 'b',
'0x20': 'pink',
'0x30': 'm',
'0x40': 'm',
'0x50': 'm',
'0x60': 'g',
'0x70': 'orange',
'0x80': 'orange',
'0x90': 'm',
'0xa0': 'b',
'0xb0': 'g',
'0xc0': 'g',
'0xd0': 'orange',
'0xe0': 'orange',
'0xf0': 'orange',
}
plt.ion()
fig = plt.figure(num = "蓝牙钥匙连接状态", figsize= (10.8,10.8),frameon= True)
gs = fig.add_gridspec(1, 1)
ax = fig.add_subplot(gs[0, 0])
colors = readData.iloc[:, 1].map(Color_map)
plt.title("Connecting Status For Bluetooth Key")
#plt.rcParams['figure.figsize']=(15, 15)
ax.axis('equal')
a,b = (0.,0.)
r = [5,10]
for r1 in r:
theta = np.arange(0,r1*np.pi,0.05)
ax.plot(a+r1*np.cos(theta),b+r1*np.sin(theta),linestyle='-.',c = 'darkgrey')
ax.spines['bottom'].set_position(('data', 0))
ax.spines['left'].set_position(('data', 0))
ax.spines['right'].set_position(('data', 0))
ax.spines['top'].set_position(('data', 0))
arr_img = plt.imread('D:\\2022\\测试工作\\蓝牙钥匙测试\\定位\\室内定位(v3.6.21).rar-1656500746516.室内定位(v3.6.21)\\车型图2.png')
imagebox = OffsetImage(arr_img, zoom=0.3)
ab = AnnotationBbox(imagebox, [0, 0],xybox=(0, 0),pad=0)
ax.add_artist(ab)
ticks = np.arange(-10,10,2)
plt.xticks(ticks)
plt.yticks(ticks)
#plt.figure(figsize=(15,15))
plt.scatter(xdata, ydata, s=150, edgecolors = None, linewidths=0, alpha=0.3,c = colors) # 画散点图,*:r表示点用*表示,颜色为红色
plt.legend()
plt.ioff()
plt.show() # 画图