濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > matplotlib之pyplot模塊坐標(biāo)軸范圍設(shè)置(autoscale(),xlim(),ylim())

matplotlib之pyplot模塊坐標(biāo)軸范圍設(shè)置(autoscale(),xlim(),ylim())

熱門(mén)標(biāo)簽:地圖地圖標(biāo)注有嘆號(hào) 螳螂科技外呼系統(tǒng)怎么用 舉辦過(guò)冬奧會(huì)的城市地圖標(biāo)注 qt百度地圖標(biāo)注 正安縣地圖標(biāo)注app 電銷(xiāo)機(jī)器人系統(tǒng)廠(chǎng)家鄭州 阿里電話(huà)機(jī)器人對(duì)話(huà) 遼寧智能外呼系統(tǒng)需要多少錢(qián) 400電話(huà)申請(qǐng)資格

matplotlib默認(rèn)根據(jù)數(shù)據(jù)系列自動(dòng)縮放坐標(biāo)軸范圍。pyplot模塊中的autoscale函數(shù)可以切換是否自動(dòng)縮放坐標(biāo)軸范圍,xlim()ylim()函數(shù)可手動(dòng)設(shè)置坐標(biāo)軸范圍。

autoscale函數(shù)

對(duì)于pyplot模塊控制坐標(biāo)軸范圍是否自動(dòng)縮放的函數(shù)為autoscale
函數(shù)簽名為matplotlib.pyplot.autoscale(enable=True, axis='both', tight=None)
參數(shù)作用及取值如下:

  • enable為布爾值,即是否自動(dòng)縮放。
  • axis取值范圍為{'both', 'x', 'y'},默認(rèn)值為'both',即作用在哪個(gè)坐標(biāo)軸。
  • tight為布爾值,默認(rèn)值為None,即是否設(shè)置邊距為0。

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

  • Axes.autoscale
  • Axes.autoscale_view
  • Axes.set_autoscale_on
  • Axes.get_autoscale_on
  • Axes.set_autoscalex_on
  • Axes.get_autoscalex_on
  • Axes.set_autoscaley_on
  • Axes.get_autoscaley_on

案例

自動(dòng)縮放坐標(biāo)軸范圍功能對(duì)比。

import matplotlib.pyplot as plt

plt.subplot(121)
plt.plot([0.5,0.5])
print(plt.gca().get_autoscale_on())
print(plt.gca().get_autoscalex_on())
print(plt.gca().get_autoscaley_on())
plt.subplot(122)
plt.plot([0.5,0.5])
plt.autoscale(False)
print(plt.gca().get_autoscale_on())
print(plt.gca().get_autoscalex_on())
print(plt.gca().get_autoscaley_on())
plt.show()

輸出:

True
True
True
False
False
False

xlim()函數(shù)

手動(dòng)設(shè)置x坐標(biāo)軸的范圍或獲取x坐標(biāo)軸的范圍。

函數(shù)簽名為matplotlib.pyplot.xlim(*args, **kwargs)。

調(diào)用簽名有三種:

  • xlim((left, right))
  • xlim(left, right)
  • xlim(left=1, right=3)

其中leftx坐標(biāo)軸左側(cè)極值,rightx坐標(biāo)軸右側(cè)極值。注意!left可以比right大!

返回值為(left, right),即坐標(biāo)軸范圍元組。

xlim()相當(dāng)于Axes.get_xlimxlim(*args, **kwargs)相當(dāng)于Axes.set_xlim。

案例

演示xlim()的調(diào)用方法。

import matplotlib.pyplot as plt

plt.figure(figsize=(14, 3))
plt.subplot(141)
plt.plot([1, 1])
print(plt.xlim())
plt.subplot(142)
plt.plot([1, 1])
plt.xlim(0, 1.5)
plt.annotate('plt.xlim(0,1.5)', (0.1, 1.001))
print(plt.xlim())
plt.subplot(143)
plt.plot([1, 1])
plt.xlim((0, 1.5))
plt.annotate('plt.xlim((0,1.5))', (0.1, 1.001))
print(plt.xlim())
plt.subplot(144)
plt.plot([1, 1])
plt.xlim(left=0, right=1.5)
plt.annotate('plt.xlim(left=0,right=1.5)', (0.1, 1.001))
print(plt.xlim())
plt.show()

輸出:

(-0.05, 1.05)
(0.0, 1.5)
(0.0, 1.5)
(0.0, 1.5)

ylim()函數(shù)

手動(dòng)設(shè)置y坐標(biāo)軸的范圍或獲取y坐標(biāo)軸的范圍。使用方法與xim()函數(shù)相似。

函數(shù)簽名為matplotlib.pyplot.ylim(*args, **kwargs)。

調(diào)用簽名有三種:

  • ylim((bottom, top))
  • ylim(bottom, top)
  • ylim(bottom=1, top=3)

其中bottomx坐標(biāo)軸左側(cè)極值,topx坐標(biāo)軸右側(cè)極值。注意!bottom可以比top大!

返回值為(bottom, top),即坐標(biāo)軸范圍元組。

ylim()相當(dāng)于Axes.get_ylimylim(*args, **kwargs)相當(dāng)于Axes.set_ylim。

案例

演示ylim()的調(diào)用方法。

import matplotlib.pyplot as plt

plt.figure(figsize=(14, 3))
plt.subplot(141)
plt.plot([1, 1])
print(plt.ylim())
plt.subplot(142)
plt.plot([1, 1])
plt.ylim(0, 1.5)
plt.annotate('plt.ylim(0,1.5)', (0.1, 1.01))
print(plt.ylim(0,1.5))
plt.subplot(143)
plt.plot([1, 1])
plt.ylim((0, 1.5))
plt.annotate('plt.ylim((0,1.5))', (0.1, 1.01))
print(plt.ylim())
plt.subplot(144)
plt.plot([1, 1])
plt.ylim(bottom=0, top=1.5)
plt.annotate('plt.ylim(bottom=0,top=1.5)', (0.1, 1.01))
print(plt.ylim())
plt.show()

輸出:

(0.945, 1.0550000000000002)
(0.0, 1.5)
(0.0, 1.5)
(0.0, 1.5)

到此這篇關(guān)于matplotlib之pyplot模塊坐標(biāo)軸范圍設(shè)置(autoscale(),xlim(),ylim())的文章就介紹到這了,更多相關(guān)matplotlib 坐標(biāo)軸范圍內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • Python matplotlib學(xué)習(xí)筆記之坐標(biāo)軸范圍

標(biāo)簽:興安盟 淘寶好評(píng)回訪(fǎng) 濟(jì)源 合肥 昭通 隨州 信陽(yáng) 阜新

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《matplotlib之pyplot模塊坐標(biāo)軸范圍設(shè)置(autoscale(),xlim(),ylim())》,本文關(guān)鍵詞  matplotlib,之,pyplot,模塊,坐標(biāo)軸,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《matplotlib之pyplot模塊坐標(biāo)軸范圍設(shè)置(autoscale(),xlim(),ylim())》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于matplotlib之pyplot模塊坐標(biāo)軸范圍設(shè)置(autoscale(),xlim(),ylim())的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    广安市| 郴州市| 本溪| 师宗县| 内乡县| 钟山县| 三亚市| 锦屏县| 墨脱县| 平罗县| 河北省| 平利县| 顺义区| 盐边县| 云安县| 铜山县| 吴桥县| 通海县| 长子县| 华安县| 扶绥县| 中宁县| 河北区| 图片| 东宁县| 赤峰市| 正蓝旗| 泉州市| 马鞍山市| 临澧县| 惠州市| 大新县| 济阳县| 池州市| 海伦市| 前郭尔| 拉孜县| 武穴市| 同心县| 鄄城县| 积石山|