ax = plt.subplot(111)# 設定刻度字型大小plt.xticks(fontsize=20)plt.yticks(fontsize=20)# 設定座標標籤字型大小ax.set_xlabel(..., fontsize=20)ax.set_ylabel(..., fontsize=20)# 設定圖例字型大小ax.legend(..., fontsize=20)選擇如何顯示刻度 ax.xaxis.set_ticks_position(‘none’) ax.yaxis.set_ticks_position(‘right’)import matplotlib.pyplot as pltimport numpy as npx = np.arange(1, 11)fig = plt.figure(1)ax1 = plt.subplot(2, 1, 1)ax2 = plt.subplot(2, 1, 2)l1, = ax1.plot(x, x*x, 'r') #這裡關鍵哦l2, = ax2.plot(x, x*x, 'b') # 注意plt.legend([l1, l2], ['first', 'second'], loc = 'upper right') #其中,loc表示位置的;plt.show()'best' : 0, (only implemented for axes legends)(自適應方式)'upper right' : 1,'upper left' : 2,'lower left' : 3,'lower right' : 4,'right' : 5,'center left' : 6,'center right' : 7,'lower center' : 8,'upper center' : 9,'center' : 10,KeywordDescriptionloca location codepropthe font property (matplotlib.font_manager.FontProperties 對象)egsong_font = matplotlib.font_manager.FontProperties(fname='simsun.ttc', size=8)fontsizethe font size (和prop互斥,不可同時使用)markerscalethe relative size of legend markers vs. originalnumpointsthe number of points in the legend for linescatterpointsthe number of points in the legend for scatter plotscatteryoffsetsa list of yoffsets for scatter symbols in legendframeonif True, draw a frame around the legend. If None, use rcfancyboxif True, draw a frame with a round fancybox. If None, use rcshadowif True, draw a shadow behind legendncolnumber of columnsborderpadthe fractional whitespace inside the legend borderlabelspacingthe vertical space between the legend entrieshandlelengththe length of the legend handleshandleheightthe length of the legend handleshandletextpadthe pad between the legend handle and textborderaxespadthe pad between the axes and legend bordercolumnspacingthe spacing between columnstitlethe legend titlebbox_to_anchorthe bbox that the legend will be anchored.bbox_transformthe transform for the bbox. transAxes if None.