plt画折线图时,plt.annotate标记折线图的点的数值。
def plot_ret(*ret_dicts):
plt.figure(figsize=(10, 5))
for ret_dict in ret_dicts:
print(ret_dict["iters"])
plt.plot([iter*4/1000 for iter in ret_dict["iters"]], ret_dict["ret"], marker='o', markersize=5, markerfacecolor='white', label=ret_dict["model"][:60]) #label=ret_dict["model"][:60]其中label比较长的需要取到所有字符,所以从24改为60
# for i, txt in enumerate(ret_dict["ret"]):
# plt.annotate("{:.3f}".format(txt), ([iter*4/1000 for iter in ret_dict["iters"]][i], ret_dict["ret"][i]))
title = ret_dict["benchmark"]
ax = plt.gca()
ax.xaxis.set_major_locator(ticker.MultipleLocator(20))
plt.legend(prop={"size":6})
plt.grid(True)
plt.title(title)
plt.xlabel("token(B)")
# plt.show()
def plot_ret_8M(*ret_dicts):
# plt.figure(figsize=(10, 5))
for ret_dict in ret_dicts:
print(ret_dict["iters"])
plt.plot([iter*8/1000 for iter in ret_dict["iters"]], ret_dict["ret"], marker='o', markersize=5, markerfacecolor='white', label=ret_dict["model"][:60])
for i, txt in enumerate(ret_dict["ret"]):
plt.annotate("{:.3f}".format(txt), ([iter*8/1000 for iter in ret_dict["iters"]][i], ret_dict["ret"][i]))
title = ret_dict["benchmark"]
ax = plt.gca()
ax.xaxis.set_major_locator(ticker.MultipleLocator(20))
plt.legend(prop={"size":6})
plt.grid(True)
plt.title(title)
plt.xlabel("token(B)")
plt.show()