日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Py之matplotlib.pyplot:matplotlib.pyplot的plt.legend函数的简介、使用方法之详细攻略

發布時間:2025/3/21 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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'
propthe font property字體參數?
fontsizethe 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’}

markerscalethe relative size of legend markers vs. original

圖例標記與原始標記的相對大小

?
markerfirstIf True (default), marker is to left of the label.

如果為True,則圖例標記位于圖例標簽的左側

?
numpointsthe number of points in the legend for line

為線條圖圖例條目創建的標記點數

?
scatterpointsthe number of points in the legend for scatter plot

為散點圖圖例條目創建的標記點數

?
scatteryoffsetsa list of yoffsets for scatter symbols in legend

為散點圖圖例條目創建的標記的垂直偏移量

?
frameonIf True, draw the legend on a patch (frame).

控制是否應在圖例周圍繪制框架

?
fancyboxIf True, draw the frame with a round fancybox.

控制是否應在構成圖例背景的FancyBboxPatch周圍啟用圓邊

?
shadowIf True, draw a shadow behind legend.

控制是否在圖例后面畫一個陰

?
framealphaTransparency of the frame.

控制圖例框架的 Alpha 透明度

?
edgecolorFrame edgecolor.?
facecolorFrame facecolor.?
ncolnumber of columns 設置圖例分為n列展示?
borderpadthe fractional whitespace inside the legend border

圖例邊框的內邊距

?
labelspacingthe vertical space between the legend entries

圖例條目之間的垂直間距

?
handlelengththe length of the legend handles?

圖例句柄的長度

?
handleheightthe height of the legend handles?

圖例句柄的高度

?
handletextpadthe pad between the legend handle and text?

圖例句柄和文本之間的間距

?
borderaxespadthe pad between the axes and legend border

軸與圖例邊框之間的距離

?
columnspacingthe spacing between columns?列間距?
titlethe legend title?
bbox_to_anchorthe bbox that the legend will be anchored.指定圖例在軸的位置?
bbox_transformthe 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函数的简介、使用方法之详细攻略的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。