Py之matplotlib.pyplot:matplotlib.pyplot的plt.legend函数的简介、使用方法之详细攻略
Py之matplotlib.pyplot:matplotlib.pyplot的plt.legend函數的簡介、使用方法之詳細攻略
?
?
?
?
目錄
matplotlib.pyplot的plt.legend函數的簡介
1、參數解釋
2、源代碼
matplotlib.pyplot的plt.legend函數的使用方法
1、基礎用法
?
?
matplotlib.pyplot的plt.legend函數的簡介
? ? ? ? ? legend模塊定義了legend類,負責繪制與軸和/或圖形相關的圖例。Legend類是一個圖例句柄和圖例文本的容器,該函數是用來給當前圖像添加圖例內容。大多數用戶通常會通過圖例函數創建圖例。圖例處理程序映射指定如何在軸或圖形中從artists(線、補丁等)創建圖例句柄。默認的圖例處理程序定義在legend_handler模塊中。雖然默認的圖例處理程序并沒有覆蓋所有的artists類型,但是可以定義自定義圖例處理程序來支持任意對象。
plt.legend(loc='best',frameon=False) #frameon參數,去掉圖例邊框 plt.legend(loc='best',edgecolor='blue') #edgecolor參數,設置圖例邊框顏色 plt.legend(loc='best',facecolor='blue') #facecolor參數,設置圖例背景顏色,若無邊框,參數無效 plt.legend(["CH", "US"], title='China VS Us') #設置圖例標題 plt.legend([p1, p2], ["CH", "US"]) #設置圖例名字及對應關系?
原始文檔:https://matplotlib.org/api/legend_api.html?highlight=legend#module-matplotlib.legend
?
1、參數解釋
| 參數 | 解釋 | 具體應用 |
| loc | Location code string, or tuple (see below).圖例所有figure位置 | plt.legend(loc='upper center') 0: ‘best' 1: ‘upper right' 2: ‘upper left' 3: ‘lower left' 4: ‘lower right' 5: ‘right' 6: ‘center left' 7: ‘center right' 8: ‘lower center' 9: ‘upper center' 10: ‘center' |
| prop | the font property字體參數 | ? |
| fontsize | the font size (used only if prop is not specified) | fontsize : int or float or {‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’} |
| markerscale | the relative size of legend markers vs. original 圖例標記與原始標記的相對大小 | ? |
| markerfirst | If True (default), marker is to left of the label. 如果為True,則圖例標記位于圖例標簽的左側 | ? |
| numpoints | the number of points in the legend for line 為線條圖圖例條目創建的標記點數 | ? |
| scatterpoints | the number of points in the legend for scatter plot 為散點圖圖例條目創建的標記點數 | ? |
| scatteryoffsets | a list of yoffsets for scatter symbols in legend 為散點圖圖例條目創建的標記的垂直偏移量 | ? |
| frameon | If True, draw the legend on a patch (frame). 控制是否應在圖例周圍繪制框架 | ? |
| fancybox | If True, draw the frame with a round fancybox. 控制是否應在構成圖例背景的FancyBboxPatch周圍啟用圓邊 | ? |
| shadow | If True, draw a shadow behind legend. 控制是否在圖例后面畫一個陰 | ? |
| framealpha | Transparency of the frame. 控制圖例框架的 Alpha 透明度 | ? |
| edgecolor | Frame edgecolor. | ? |
| facecolor | Frame facecolor. | ? |
| ncol | number of columns 設置圖例分為n列展示 | ? |
| borderpad | the fractional whitespace inside the legend border 圖例邊框的內邊距 | ? |
| labelspacing | the vertical space between the legend entries 圖例條目之間的垂直間距 | ? |
| handlelength | the length of the legend handles? 圖例句柄的長度 | ? |
| handleheight | the height of the legend handles? 圖例句柄的高度 | ? |
| handletextpad | the pad between the legend handle and text? 圖例句柄和文本之間的間距 | ? |
| borderaxespad | the pad between the axes and legend border 軸與圖例邊框之間的距離 | ? |
| columnspacing | the spacing between columns?列間距 | ? |
| title | the legend title | ? |
| bbox_to_anchor | the bbox that the legend will be anchored.指定圖例在軸的位置 | ? |
| bbox_transform | the transform for the bbox. transAxes if None. | ? |
?
2、源代碼
更新……
?
def legend Found at: matplotlib.pyplot@_copy_docstring_and_deprecators(Axes.legend) def legend(*args, **kwargs):return gca().legend(*args, **kwargs)# Autogenerated by boilerplate.py. Do not edit as changes will be lost.?
?
?
matplotlib.pyplot的plt.legend函數的使用方法
1、基礎用法
plt.figure() col_cou_len=len(Keys)plt.pie(x=Values,labels=Keys,colors=cols[:col_cou_len], startangle=90,shadow=True,autopct='%1.3f%%') plt.title(tit_name)plt.legend()plt.show()?
?
?
?
?
?
?
?
?
?
?
?
總結
以上是生活随笔為你收集整理的Py之matplotlib.pyplot:matplotlib.pyplot的plt.legend函数的简介、使用方法之详细攻略的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ML之FE:基于BigMartSales
- 下一篇: 成功解决成功解决return _iter