写论文,需要画数据分析图:
- 用柱状图描述算法执行时间
- 用折线图描述性能改进
示例代码:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocatorSecurity = ["128", "192", "256"]Alg1 = {"Others": [55, 99, 170],"Ours": [33, 44, 55],"Ratio": [23.4, 45.6, 78.9]}################################################################# 双轴:https://zhuanlan.zhihu.com/p/343719623
# 图形:https://blog.csdn.net/weixin_45891612/article/details/129082746
# 颜色:https://blog.csdn.net/weixin_43697287/article/details/88876680
# 花纹:https://matplotlib.org/2.0.2/examples/pylab_examples/hatch_demo.html
# 图例:https://blog.csdn.net/Wannna/article/details/102751689# 柱状图坐标
size = len(Security)
x = np.arange(size)
width_bar = 0.2
Alg_x = x
Ours_x = x + width_bar
Security_x = x + width_bar/2# 刻度间隔
y1_major_locator=MultipleLocator(25)
y2_major_locator=MultipleLocator(10)bar_color_1 = '#ff8080'
bar_color_2 = '#8080ff'
plot_color = '#111111'################################################################fig = plt.figure()
ax1 = fig.add_subplot(111)ax1.bar(Alg_x, Alg1["Others"], width=width_bar, color=bar_color_1, hatch="--", label="Others")
ax1.bar(Ours_x, Alg1["Ours"], width=width_bar, color=bar_color_2, hatch="//", label="Ours")
ax1.set_ylim(bottom=0, top=250)
ax1.yaxis.set_major_locator(y1_major_locator)ax1.set_ylabel('Running Time (clocks)')
ax1.set_xlabel('XXX (bits)')
ax1.legend(loc=2)ax2 = ax1.twinx() # this is the important functionax2.plot(Security_x, Alg1["Ratio"], color=plot_color, marker="v", label="Relative Improvement")
ax2.set_ylim(bottom=0, top=100)
ax2.yaxis.set_major_locator(y2_major_locator)
ax2.set_ylabel('Percentage (%)')
ax2.legend(loc=1)for i in range(size): ##向曲线上的点添加数据标签,利用text函数plt.text(Security_x[i], Alg1["Ratio"][i]+1.3, Alg1["Ratio"][i], ha='center', va='bottom', fontsize=10, color=plot_color) plt.xticks(Security_x, labels=Security)
plt.title("Alg1")
plt.show()
绘制结果应当存储为 .eps
格式,pdflatex
将它编译为 .pdf
矢量图片。