最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

關(guān)于matplotlib-legend 位置屬性 loc 使用說明

 更新時間:2020年05月16日 11:24:55   作者:攔路雨g  
這篇文章主要介紹了關(guān)于matplotlib-legend 位置屬性 loc 使用說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

在使用matplotlib畫圖時,少不了對性能圖形做出一些說明和補(bǔ)充。一般情況下,loc屬性設(shè)置為'best'就足夠應(yīng)付了

plt.legend(handles = [l1, l2,], labels = ['a', 'b'], loc = 'best')

或直接loc = 0

plt.legend(handles = [l1, l2,], labels = ['a', 'b'], loc = 0)

除'best',另外loc屬性有:

'upper right', 'upper left', 'lower left', 'lower right', 'right', 'center left', 'center right', 'lower center', 'upper center', 'center'

不說太多,上面是全部的快捷使用,滿足一般需求。

demo:

import matplotlib.pyplot as plt
import numpy as np
 
# 繪制普通圖像
x = np.linspace(-1, 1, 50)
y1 = 2 * x + 1
y2 = x**2
 
plt.figure()
# 在繪制時設(shè)置lable, 逗號是必須的
l1, = plt.plot(x, y1, label = 'line')
l2, = plt.plot(x, y2, label = 'parabola', color = 'red', linewidth = 1.0, linestyle = '--')
 
# 設(shè)置坐標(biāo)軸的取值范圍
plt.xlim((-1, 1))
plt.ylim((0, 2))
 
# 設(shè)置坐標(biāo)軸的lable
plt.xlabel('X axis')
plt.ylabel('Y axis')
 
# 設(shè)置x坐標(biāo)軸刻度, 原來為0.25, 修改后為0.5
plt.xticks(np.linspace(-1, 1, 5))
# 設(shè)置y坐標(biāo)軸刻度及標(biāo)簽, $$是設(shè)置字體
plt.yticks([0, 0.5], ['$minimum$', 'normal'])
 
# 設(shè)置legend
plt.legend(handles = [l1, l2,], labels = ['a', 'b'], loc = 'best')
plt.show()

運(yùn)行結(jié)果:

補(bǔ)充知識:設(shè)置圖列(key/legend)的位置和大小 --gnuplot

先看幾個例子:

//不顯示圖例。
unset key
//設(shè)置圖例 顯示在圖形(內(nèi))的頂部居中,并且多個圖例水平顯示。
set key top horizontal center
//設(shè)置圖例 顯示在圖形(外)的頂部居中,并且多個圖例水平顯示。
set key top outside horizontal center
//設(shè)置圖例 顯示的字體并加粗。
set key font "Times,18,Bold"
//調(diào)整圖例行間隔
set key spacing 3
//調(diào)整圖例中線段示例長度
set key samplen 2

set key 的語法規(guī)則

Syntax: 
   set key {on|off} {default}
       {{inside | outside} | {lmargin | rmargin | tmargin | bmargin}
        | {at <position>}}
       {left | right | center} {top | bottom | center}
       {vertical | horizontal} {Left | Right}
       {{no}reverse} {{no}invert}
       {samplen <sample_length>} {spacing <vertical_spacing>}
       {width <width_increment>}
       {height <height_increment>}
       {{no}autotitle {columnheader}}
       {title "<text>"} {{no}enhanced}
       {{no}box { {linestyle | ls <line_style>}
            | {linetype | lt <line_type>}
             {linewidth | lw <line_width>}}}
   unset key
   show key

Elements within the key are stacked according to vertical or horizontal. In the case of vertical, the key occupies as few columns as possible. That is, elements are aligned in a column until running out of vertical space at which point a new column is started. In the case of horizontal, the key occupies as few rows as possible.

圖例是依據(jù)我們設(shè)置的水平顯示或垂直顯示進(jìn)行堆疊式地顯示。

對于垂直顯示,pnuplot會占用盡可能少的行來放置我們的圖例,當(dāng)圖例在一行顯示不下時,它會另啟一行來顯示。

對于水平顯示方式,pnuplot會占用盡可能少的列來放置我們的圖例,當(dāng)圖例在一列顯示不下時,它會另啟一列來放置。

The vertical spacing between lines is controlled by spacing. The spacing is set equal to the product of the pointsize, the vertical tic size, and vertical_spacing. The program will guarantee that the vertical spacing is no smaller than the character height.

The defaults for set key are on, right, top, vertical, Right, noreverse, noinvert, samplen 4, spacing 1.25, title “”, and nobox.

以上這篇關(guān)于matplotlib-legend 位置屬性 loc 使用說明就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • python環(huán)境的報錯解決方法

    python環(huán)境的報錯解決方法

    這篇文章主要為大家介紹了python環(huán)境的報錯解決方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-08-08
  • Python中的二維列表使用及說明

    Python中的二維列表使用及說明

    這篇文章主要介紹了Python中的二維列表使用及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • 實例講解Python腳本成為Windows中運(yùn)行的exe文件

    實例講解Python腳本成為Windows中運(yùn)行的exe文件

    在本篇文章里小編給大家分享了關(guān)于Python腳本成為Windows中運(yùn)行的exe文件的相關(guān)知識點(diǎn)內(nèi)容,有興趣的朋友們學(xué)習(xí)下。
    2019-01-01
  • 對Python3使運(yùn)行暫停的方法詳解

    對Python3使運(yùn)行暫停的方法詳解

    今天小編就為大家分享一篇對Python3使運(yùn)行暫停的方法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-02-02
  • 套娃式文件夾如何通過Python批量處理

    套娃式文件夾如何通過Python批量處理

    這篇文章主要介紹了套娃式文件夾如何通過Python批量處理,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • Python定義一個函數(shù)的方法

    Python定義一個函數(shù)的方法

    這篇文章主要介紹了Python定義一個函數(shù)的方法及相關(guān)實例,需要的朋友們可以學(xué)習(xí)參考下。
    2020-06-06
  • 詳解python之異步編程

    詳解python之異步編程

    這篇文章主要為大家介紹了python之異步編程,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助<BR>
    2021-12-12
  • Python必須了解的35個關(guān)鍵詞

    Python必須了解的35個關(guān)鍵詞

    這篇文章主要介紹了Python必須了解的35個關(guān)鍵詞,文中講解非常細(xì)致,幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • 總結(jié)python爬蟲抓站的實用技巧

    總結(jié)python爬蟲抓站的實用技巧

    很多人學(xué)用python,用得最多的還是各類爬蟲腳本:有寫過抓代理本機(jī)驗證的腳本,有寫過自動收郵件的腳本,還有寫過簡單的驗證碼識別的腳本,那么我們今天就來總結(jié)下python爬蟲抓站的一些實用技巧。
    2016-08-08
  • 利用Selenium添加cookie實現(xiàn)自動登錄的示例代碼(fofa)

    利用Selenium添加cookie實現(xiàn)自動登錄的示例代碼(fofa)

    這篇文章主要介紹了利用Selenium添加cookie實現(xiàn)自動登錄的示例代碼(fofa),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05

最新評論

革吉县| 宜丰县| 漯河市| 烟台市| 建水县| 金坛市| 葫芦岛市| 巍山| 南平市| 介休市| 苏尼特左旗| 新宁县| 华亭县| 武穴市| 广汉市| 神农架林区| 策勒县| 松原市| 乌海市| 德江县| 彰化市| 云浮市| 邹平县| 日喀则市| 青河县| 永和县| 方山县| 晋中市| 图们市| 石城县| 东兴市| 平乐县| 卢龙县| 甘南县| 沈阳市| 顺平县| 万荣县| 临朐县| 永清县| 吕梁市| 吴江市|