求解为何会报错,定位是ax1.set_ylabel这一行。
import pandas as pd
from tkinter import messagebox, filedialog
import matplotlib.pyplot as plt
messagebox.showinfo("提示", "请先选择数据")
file_path = filedialog.askopenfilename()
DataFrame = pd.read_excel(file_path)
fig = plt.figure()
ax1 = fig.subplots()
ax2 = ax1.twinx()
line1 = ax1.plot(DataFrame[['time']], DataFrame[['L']], 'r-', label='L')
line2 = ax2.plot(DataFrame[['time']], DataFrame[['S0']], 'b--', label='S0 ANGLE')
ax1.set_xlabel('TimeSpan (s)')
ax1.set_ylabel('L (mm)', 'r-')
ax2.set_ylabel('S0 ANGLE (deg)', 'b--')
lines = line1 + line2
labels = [h.get_label() for h in lines]
plt.legend(lines, labels, loc='best')
plt.show()
AttributeError: 'str' object has no attribute 'items'