import matplotlib.pyplot as plt from matplotlib import font_manager as fm def load_data(filename): """ Load data from a file. Assumes that each line in the file is a float value. """ with open(filename, 'r') as file: data = file.read().split() data = [float(i) for i in data] return data def main(): # 加载数据 edf_data = [0.83, 1.35, 1.88, 2.36, 1.9] llf_data = [0.45, 0.4, 0.52, 0.97, 0.9] # 设置X轴的数据点 x_labels = [50, 60, 70, 80, 90] # 确保数据与这些标签相匹配 font_properties = fm.FontProperties(family='Times New Roman', size=18) plt.rcParams.update({'font.size': 18, 'font.family': 'Times New Roman'}) # 创建图形和绘制数据 plt.figure(figsize=(10, 5)) ax = plt.gca() # 获取当前的Axes对象ax ax.set_facecolor('#f0f0f0') # 设置浅灰色背景 plt.plot(x_labels, edf_data, marker='s', linestyle='-', color='#C8503D', markersize=8, label='EDF') plt.plot(x_labels, llf_data, marker='^', linestyle='-', color='#00008B', markersize=8, label='LLF') # 添加标题、标签和图例 plt.title('5KB-1.5*Deadline', fontsize=20, fontproperties=font_properties) plt.xlabel('Load (% of maximum RPS)', fontproperties=font_properties) plt.ylabel('Deadline Miss Rate (%)', fontproperties=font_properties) plt.legend(prop=font_properties) # 设置X轴刻度 plt.xticks(range(50, 91, 10)) # 设置网格 plt.grid(True) # 移除边框的四边刻度线 plt.tick_params(axis='both', which='both', length=0) # 移除刻度线 # 显示图形 plt.show() if __name__ == "__main__": main()