用matplot打印图表,导入库
import pandas as pd import matplotlib import matplotlib.pyplot as plt import numpy as np from matplotlib.ticker import FormatStrFormatter
打印表格
# Plotting precision and validation precision over epochs要打印什么表格,xy轴
plt.figure(figsize=(10, 8)) #表格大小
matplotlib.rcParams['font.family'] = 'sans-serif' #规定字体
# Training precision
plt.plot(data['epoch'], data['precision'], label='Training Precision', color='blue',marker='o')
#csv表格里的表头叫什么,用什么颜色的线,当中要不要dot
# Validation Accuracy
plt.plot(data['epoch'], data['val_precision'], label='Validation Precision', color='red',marker='o')
# Setting titles and labels
plt.title('Training and Validation Precision over Epochs',fontsize=14)
#字体大小fontsize
plt.xlabel('Epoch',fontsize=12)
plt.ylabel('Precision',fontsize=12)
#xy轴叫什么,字体大小
plt.grid(True)
#显示网格
# Set the legend to be in the upper right corner
plt.legend(loc='lower center')
#legend放在那里,左上左下,右上右下,中间上下,还有其他
# Setting x-axis ticks interval to 5
plt.xticks(list(range(0, data['epoch'].max() + 1, 5)))‘
#x轴的间隔多少,间距多少,最大最小值多少
plt.yticks(np.linspace(0.50, 1.00, 9))
plt.gca().yaxis.set_major_formatter(FormatStrFormatter('%.2f'))
#y轴最大最小值范围,0.5-1.00,9个间隔,保留两位小数
plt.show()
#一定要show才会显示!