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

matplotlib grid()設(shè)置網(wǎng)格線外觀的實(shí)現(xiàn)

 更新時(shí)間:2021年02月22日 16:17:08   作者:mighty13  
這篇文章主要介紹了matplotlib grid()設(shè)置網(wǎng)格線外觀的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

grid()函數(shù)概述

grid()函數(shù)用于設(shè)置繪圖區(qū)網(wǎng)格線。
grid()的函數(shù)簽名為matplotlib.pyplot.grid(b=None, which='major', axis='both', **kwargs)。
grid()的參數(shù)如下:

  • b:是否顯示網(wǎng)格線。布爾值或None,可選參數(shù)。如果沒有關(guān)鍵字參數(shù),則bTrue,如果bNone且沒有關(guān)鍵字參數(shù),相當(dāng)于切換網(wǎng)格線的可見性。
  • which:網(wǎng)格線顯示的尺度。字符串,可選參數(shù),取值范圍為{'major', 'minor', 'both'},默認(rèn)為'both'。'major'為主刻度、'minor'為次刻度。
  • axis:選擇網(wǎng)格線顯示的軸。字符串,可選參數(shù),取值范圍為{'both', 'x', 'y'},默認(rèn)為'both'`。
  • **kwargsLine2D線條對(duì)象屬性。

grid()的返回值為None。

grid()函數(shù)演示

在這里插入圖片描述

import matplotlib.pyplot as plt

plt.subplot(341)
# grid()默認(rèn)樣式
plt.plot([1, 1])
plt.grid()
plt.annotate('grid()', (0, 1))
plt.subplot(342)
# 因?yàn)槟J(rèn)沒有網(wǎng)格線,所以grid(None)顯示網(wǎng)格線
plt.plot([1, 1])
plt.grid(None)
plt.annotate('grid(None)', (0, 1))
plt.subplot(343)
# 因?yàn)樵O(shè)置了網(wǎng)格線,所以grid(None)切換為不顯示網(wǎng)格線
plt.plot([1, 1])
plt.grid(True)
plt.grid(None)
plt.annotate('grid(None)', (0, 1))
plt.subplot(344)
# 因?yàn)槟J(rèn)沒有網(wǎng)格線
plt.plot([1, 1])
plt.annotate("default", (0, 1))
plt.subplot(345)
# 只顯示主刻度網(wǎng)格線
plt.plot([1, 1])
plt.grid(which='major')
plt.annotate("which='major'", (0, 1))
plt.subplot(346)
# 只顯示次刻度網(wǎng)格線,因?yàn)闆]有次刻度,所以無網(wǎng)格線
plt.plot([1, 1])
plt.grid(which='minor')
plt.annotate("which='minor'", (0, 1))
plt.subplot(347)
# 同時(shí)顯示主刻度、次刻度網(wǎng)格線
plt.plot([1, 1])
plt.grid(which='both')
plt.annotate("which='both'", (0, 1))
plt.subplot(348)
plt.plot([1, 1])
# 默認(rèn)同時(shí)顯示主刻度、次刻度網(wǎng)格線
plt.grid()
plt.annotate("default", (0, 1))
plt.subplot(349)
# 只顯示x軸網(wǎng)格線
plt.plot([1, 1])
plt.grid(axis='x')
plt.annotate("axis='x'", (0, 1))
plt.subplot(3,4,10)
# 只顯示y軸網(wǎng)格線
plt.plot([1, 1])
plt.grid(axis='y')
plt.annotate("axis='y'", (0, 1))
plt.subplot(3,4,11)
# 同時(shí)顯示xy軸網(wǎng)格線
plt.plot([1, 1])
plt.grid(axis='both')
plt.annotate("axis='both'", (0, 1))
plt.subplot(3,4,12)
# 默認(rèn)顯示xy軸網(wǎng)格線
plt.plot([1, 1])
plt.grid()
plt.annotate("default", (0, 1))
plt.show()

原理

pyplot.grid()其實(shí)調(diào)用的是gca().grid(),即Aexs.grid()。

底層相關(guān)函數(shù)有:
Axis.grid()

Axes.grid()源碼(matplotlib/Axes/_base.py

def grid(self, b=None, which='major', axis='both', **kwargs):
    cbook._check_in_list(['x', 'y', 'both'], axis=axis)
    if axis in ['x', 'both']:
      self.xaxis.grid(b, which=which, **kwargs)
    if axis in ['y', 'both']:
      self.yaxis.grid(b, which=which, **kwargs)

xaxisXAxis類的實(shí)例,yaxisYAxis類的實(shí)例,XAxisYAxis類的基類為Axis。

Axis.grid()源碼(matplotlib/axis.py

def grid(self, b=None, which='major', **kwargs):
  if b is not None:
    if 'visible' in kwargs and bool(b) != bool(kwargs['visible']):
      raise ValueError(
        "'b' and 'visible' specify inconsistent grid visibilities")
    if kwargs and not b: # something false-like but not None
      cbook._warn_external('First parameter to grid() is false, '
                 'but line properties are supplied. The '
                 'grid will be enabled.')
      b = True
  which = which.lower()
  cbook._check_in_list(['major', 'minor', 'both'], which=which)
  gridkw = {'grid_' + item[0]: item[1] for item in kwargs.items()}
  if 'grid_visible' in gridkw:
    forced_visibility = True
    gridkw['gridOn'] = gridkw.pop('grid_visible')
  else:
    forced_visibility = False

  if which in ['minor', 'both']:
    if b is None and not forced_visibility:
      gridkw['gridOn'] = not self._minor_tick_kw['gridOn']
    elif b is not None:
      gridkw['gridOn'] = b
    self.set_tick_params(which='minor', **gridkw)
  if which in ['major', 'both']:
    if b is None and not forced_visibility:
      gridkw['gridOn'] = not self._major_tick_kw['gridOn']
    elif b is not None:
      gridkw['gridOn'] = b
    self.set_tick_params(which='major', **gridkw)
  self.stale = True

到此這篇關(guān)于matplotlib grid()設(shè)置網(wǎng)格線外觀的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)matplotlib grid()網(wǎng)格線內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python在新的圖片窗口顯示圖片(圖像)的方法

    python在新的圖片窗口顯示圖片(圖像)的方法

    今天小編就為大家分享一篇python在新的圖片窗口顯示圖片(圖像)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-07-07
  • Python實(shí)現(xiàn)下雪效果的示例代碼

    Python實(shí)現(xiàn)下雪效果的示例代碼

    turtle是Python編程語言中的一個(gè)模塊,用于繪制圖形和圖形動(dòng)畫,本文主要為大家詳細(xì)介紹了Python如何使用turtle實(shí)現(xiàn)張萬森下雪了的效果,感興趣的可以了解下
    2023-12-12
  • Python?numpy邏輯運(yùn)算方法舉例介紹

    Python?numpy邏輯運(yùn)算方法舉例介紹

    這篇文章主要介紹了Python?numpy邏輯運(yùn)算方法的相關(guān)資料,NumPy中提供了一系列邏輯運(yùn)算方法,用于執(zhí)行逐元素的邏輯和比較操作,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-10-10
  • python miniWeb框架搭建過程詳解

    python miniWeb框架搭建過程詳解

    這篇文章主要介紹了python miniWeb框架搭建,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-10-10
  • Python3.5基礎(chǔ)之NumPy模塊的使用圖文與實(shí)例詳解

    Python3.5基礎(chǔ)之NumPy模塊的使用圖文與實(shí)例詳解

    這篇文章主要介紹了Python3.5基礎(chǔ)之NumPy模塊的使用,結(jié)合圖文與實(shí)例形式詳細(xì)分析了Python3.5中Numpy模塊的原理、功能、使用方法及操作注意事項(xiàng),需要的朋友可以參考下
    2019-04-04
  • python設(shè)計(jì)微型小說網(wǎng)站(基于Django+Bootstrap框架)

    python設(shè)計(jì)微型小說網(wǎng)站(基于Django+Bootstrap框架)

    這篇文章主要介紹了python設(shè)計(jì)微型小說網(wǎng)站(基于Django+Bootstrap框架),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-07-07
  • Python中keyboard的使用之監(jiān)控鍵盤的按鍵輸入

    Python中keyboard的使用之監(jiān)控鍵盤的按鍵輸入

    Python的keyboard模塊是一個(gè)強(qiáng)大的工具,用于監(jiān)聽和處理鍵盤事件,該模塊允許程序獲取鍵盤輸入,并執(zhí)行相應(yīng)操作,如監(jiān)聽、捕獲熱鍵、模擬鍵位和獲取鍵盤狀態(tài)等,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-11-11
  • python內(nèi)置函數(shù)compile(),complex()的使用

    python內(nèi)置函數(shù)compile(),complex()的使用

    這篇文章主要為大家詳細(xì)介紹了python內(nèi)置函數(shù)compile(),complex()的使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • python中return的返回和執(zhí)行實(shí)例

    python中return的返回和執(zhí)行實(shí)例

    今天小編就為大家分享一篇python中return的返回和執(zhí)行實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • python代碼能做成軟件嗎

    python代碼能做成軟件嗎

    在本篇內(nèi)容里小編給大家分享的是一篇關(guān)于把python代碼做成軟件的方法,有興趣的朋友們可以閱讀下。
    2020-07-07

最新評(píng)論

南充市| 佳木斯市| 合川市| 剑阁县| 内丘县| 阿图什市| 大庆市| 鞍山市| 临夏市| 湛江市| 曲水县| 兖州市| 邢台市| 闵行区| 临朐县| 濮阳市| 北碚区| 岢岚县| 道真| 区。| 白河县| 元阳县| 万荣县| 阿拉善右旗| 龙胜| 信丰县| 汽车| 大田县| 利辛县| 崇明县| 凉城县| 米易县| 泗水县| 天祝| 大悟县| 阿城市| 汉沽区| 浦县| 永定县| 南江县| 义乌市|