在 matplotlib 中 legend 用於設置圖形中的圖例,其常見用法如下:
legend(loc # Location code string, or tuple (see below). # 圖例所有figure位置。
labels # 標簽名稱。 prop # the font property. # 字體參數 fontsize # the font size (used only if prop is not specified). # 字號大小。 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.
1、簡單顯示圖例
legend()
2、設置位置,圖例類顯示列數等
legend(loc, ncol, **)
matplotlib 的 legend 官網:https://matplotlib.org/users/legend_guide.html
參考:https://blog.csdn.net/helunqu2017/article/details/78641290