|
- import matplotlib.pyplot as plt
- plt.rc('font', family='Times New Roman')
-
-
- def make_patch_spines_invisible(ax):
- ax.set_frame_on(True)
- ax.patch.set_visible(False)
- for sp in ax.spines.values():
- sp.set_visible(False)
-
-
- fig, host = plt.subplots()
- fig.subplots_adjust(right=0.75)
-
- par1 = host.twinx()
-
- x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
- y = [2.66, 2.75, 2.59, 2.60, 2.73, 2.78, 2.67, 2.89, 2.64]
- yerror = [0.03, 0.016, 0.017, 0.01, 0.002, 0.03, 0.02, 0.005, 0.005]
-
- y_2 = [0.6, 1.26, 1.875, 2.47, 3.1, 3.79, 4.54, 4.8, 5.725]
- yerror_2 = [0.03, 0.01, 0.03, 0.03, 0.07, 0.13, 0.0017, 0.36, 0.24]
-
- p1 = host.errorbar(x, y, yerr=yerror, fmt="ro-", label="Test Error")
- host.axhline(y[2], xmin=0, xmax=0.3, color="r", linestyle="dashed", linewidth=1.5)
- # p2 = par1.errorbar(x, y_2, yerr=yerror, fmt="ro-", label="Accuracy")
- #
- # p1, = host.plot([0, 1, 2], [0, 1, 2], "b-", label="Accuracy")
- p2= par1.errorbar(x, y_2, yerr=yerror_2, fmt="b^-", label="Search time")
- par1.axhline(y_2[2], xmin=0.3, xmax=1., color="b", linestyle="dashed", linewidth=1.5)
-
- host.grid(linestyle='-.', linewidth=1)
- host.set_xlim(0.5, 9.5)
- host.set_ylim(2.5, 3.0)
- par1.set_ylim(0, 6)
-
-
- host.set_xlabel("Pruning step", fontsize=17)
- host.set_ylabel("Test Error", fontsize=17)
- par1.set_ylabel("Search time (GPU hours)", fontsize=17)
-
- host.yaxis.label.set_color('r')
- par1.yaxis.label.set_color('b')
-
- tkw = dict(size=4, width=1.5,labelsize=15)
- host.tick_params(axis='y', colors='r', **tkw)
- par1.tick_params(axis='y', colors='b', **tkw)
- host.tick_params(axis='x', **tkw)
-
- lines = [p1, p2]
-
- host.legend(lines, [l.get_label() for l in lines], loc=2, fontsize=17)
-
- ax = host
- ax.spines['bottom'].set_linewidth(2)
- ax.spines['left'].set_linewidth(2)
- ax.spines['right'].set_linewidth(2)
- ax.spines['top'].set_linewidth(2)
-
- plt.tight_layout()
- plt.savefig('axes.pdf')
- plt.show()
|