# -*- coding:utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
x_axis_data = [1, 2, 3, 4, 5, 6, 7] # x
y_axis_data = [68, 69, 79, 71, 80, 70, 66] # y
if __name__ == '__main__':
# =>添加标签
for x, y in zip(x_axis_data, y_axis_data):
plt.text(x, y + 0.3, '%.00f' % y, ha='center', va='bottom', fontsize=7.5) # y_axis_data1加标签数据
# =>绘图
plt.plot(x_axis_data, y_axis_data, 'b*--', alpha=0.5, linewidth=1, label='acc') # 'bo-'表示蓝色实线,数据点实心原点标注
# =>添加label
plt.legend() # 显示上面的label
plt.xlabel('time') # x_label
plt.ylabel('number') # y_label
# plt.ylim(-1,1)#仅设置y轴坐标范围
plt.show()
# plot中参数的含义分别是横轴值,纵轴值,线的形状('s'方块,'o'实心圆点,'*'五角星 ...,颜色,透明度,线的宽度和标签)
# -*- coding:utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
# epoch,acc,loss,val_acc,val_loss
x_axis_data = [1, 2, 3, 4, 5, 6, 7]
y_axis_data1 = [68.72, 69.17, 69.26, 69.63, 69.35, 70.3, 66.8]
y_axis_data2 = [71, 73, 52, 66, 74, 82, 71]
y_axis_data3 = [82, 83, 82, 76, 84, 92, 81]
if __name__ == '__main__':
# =>绘图
plt.plot(x_axis_data, y_axis_data1, 'b*--', alpha=0.5, linewidth=1, label='acc')
plt.plot(x_axis_data, y_axis_data2, 'rs--', alpha=0.5, linewidth=1, label='acc')
plt.plot(x_axis_data, y_axis_data3, 'go--', alpha=0.5, linewidth=1, label='acc')
# =>标签
for a, b in zip(x_axis_data, y_axis_data1):
plt.text(a, b, str(b), ha='center', va='bottom', fontsize=8) # ha='center', va='top'
for a, b1 in zip(x_axis_data, y_axis_data2):
plt.text(a, b1, str(b1), ha='center', va='bottom', fontsize=8)
for a, b2 in zip(x_axis_data, y_axis_data3):
plt.text(a, b2, str(b2), ha='center', va='bottom', fontsize=8)
# =>添加label
plt.legend() # 显示上面的label
plt.xlabel('time') # x_label
plt.ylabel('number') # y_label
# plt.ylim(-1,1)#仅设置y轴坐标范围
plt.show()
# plot中参数的含义分别是横轴值,纵轴值,线的形状('s'方块,'o'实心圆点,'*'五角星 ...,颜色,透明度,线的宽度和标签)
# 's': 方块状 'o': 实心圆 '^': 正三角形 'v': 反正三角形 '+': 加好
# '*': 星 号 'x': x号 'p': 五角星 '1': 三脚架标记 '2': 三脚架标记
# -*- coding:utf-8 -*-
import matplotlib.pyplot as plt
plt.rcParams["font.sans-serif"] = ["SimHei"] # 设置字体
plt.rcParams["axes.unicode_minus"] = False # 该语句解决图像中的“-”负号的乱码问题
width = 0.4
y = [5.203, 9.232, 23.965, 47.282]
x_labels = ["RTX4000*2", "RTX4000", "GTX1050", "950M"]
x = range(len(y))
if __name__ == '__main__':
# =>绘制柱状图
plt.bar(x=x, height=y, width=width, alpha=0.7, color='red', label="未优化")
# =>横坐标labels
plt.xticks([i for i in x], x_labels)
# =>在每个条形顶部添加数值
for i, j in zip(x, y):
plt.text(i, j + 0.01, "%.3f" % j, ha="center", va="bottom", fontsize=10)
# =>设置label
plt.legend() # 显示上面的labe
plt.xlabel("显卡类型")
plt.ylabel("处理时间(s)")
plt.show()
# -*- coding:utf-8 -*-
import matplotlib.pyplot as plt
plt.rcParams["font.sans-serif"] = ["SimHei"] # 设置字体
plt.rcParams["axes.unicode_minus"] = False # 该语句解决图像中的“-”负号的乱码问题
width = 0.4
y1 = [5.203, 9.232, 23.965, 47.282]
y2 = [3.952, 5.102, 10.673, 17.520]
x_labels = ["RTX4000*2", "RTX4000", "GTX1050", "950M"]
x = range(len(y1))
if __name__ == '__main__':
plt.bar(x=x, height=y1, width=width, alpha=0.7, color='red', label="未优化")
plt.bar([i+width for i in x], height=y2, width=width, alpha=0.7, color='green', label="优化")
plt.xticks([i+width/2 for i in x], x_labels)
# 在每个条形顶部添加数值
for i, j in zip(x, y1):
plt.text(i, j + 0.01, "%.3f" % j, ha="center", va="bottom", fontsize=10)
for i, j in zip([i+width for i in x], y2):
plt.text(i, j + 0.01, "%.3f" % j, ha="center", va="bottom", fontsize=10)
# 设置label
plt.legend()
plt.xlabel("显卡类型")
plt.ylabel("处理时间(s)")
plt.show()
三、----图