1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| importmatplotlib.pyplotasplt importmatplotlib.font_managerasfont_manager importnumpyasnp importpandasaspd frommatplotlib.font_managerimportFontProperties
font_props = font_manager.FontProperties(weight='bold')
plt.rcParams['font.family'] ='Times New Roman' plt.rcParams['font.sans-serif'] = ['SimHei'] plt.rcParams['axes.unicode_minus'] =False
if__name__ =='__main__': fig = plt.figure(figsize=(7, 6)) ax1 = fig.add_subplot()
x_data = ['10','20','30','40','50','60'] Y1= [2.3,2,2.4,3,3.5,3] Y2= [2.3,2,2.5,3,2.8,2.9] Y3= [3,3.5,3.6,3.4,3.8,4]
line,=ax1.plot(x_data, Y1, color='royalblue', marker='s', linewidth=2, markersize=8, markerfacecolor='none', markeredgewidth=2,label='Y1') line1,=ax1.plot(x_data, Y2, color='darkorange', marker='^', linewidth=2, markersize=8, markerfacecolor='none', markeredgewidth=2,label='Y2') line2,=ax1.plot(x_data, Y3, color='slategray', marker='o', linewidth=2, markersize=8, markerfacecolor='none', markeredgewidth=2,label='Y3')
ax1.set_xlabel("XXX",fontsize=20,weight='bold') ax1.set_ylabel("YYY",fontsize=20,weight='bold')
ax1.tick_params(axis='y', direction='in', labelsize=18) ax1.tick_params(axis='x', direction='in', labelsize=18)
ax1.yaxis.grid(True)
ax2 = ax1.twiny()
ax2.tick_params(axis='x', which='both', colors='white', labelsize=1,bottom=False, top=False, left=False, right=False,labelbottom=False, labelleft=False)
legend = [line,line1,line2] labels = [l.get_label()forlinlegend] legend = ax1.legend(legend, labels) font_props = FontProperties(weight='bold',size=13) fortextinlegend.get_texts(): text.set_font_properties(font_props)
plt.savefig('pngs/pic16.png', dpi=600, bbox_inches='tight', pad_inches=0)
|