當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Matplotlib.axis.Axis.get_label_position()用法及代碼示例

Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。它是Python中令人驚歎的可視化庫,用於數組的2D圖,並用於與更廣泛的SciPy堆棧配合使用。

Matplotlib.axis.Axis.get_label_position()函數

matplotlib庫的軸模塊中的Axis.get_label_position()函數用於獲取標簽位置。

用法: Axis.get_label_position(self) 

參數:此方法不接受任何參數。

返回值:此方法返回標簽位置。



以下示例說明了matplotlib.axis中的matplotlib.axis.Axis.get_label_position()函數:

範例1:

Python3

# Implementation of matplotlib function  
from matplotlib.axis import Axis 
import numpy as np 
import matplotlib.pyplot as plt 
   
fig, ax2 = plt.subplots(sharex = True) 
fig.subplots_adjust(left=0.2, wspace=0.6) 
box = dict(facecolor='green', pad=5, alpha=0.2) 
   
ax2.plot(20*np.random.rand(10)) 
ax2.xaxis.set_label_text('X - Label', bbox=box) 
ax2.set_xlim(0, 10) 
print("Position of Label:",ax2.xaxis.get_label_position()) 
    
fig.suptitle("Matplotlib.axis.Axis.get_label_position()\ 
Function Example", fontsize = 12, fontweight ='bold')  
  
plt.show()

輸出:

Position of Label:bottom

範例2:

Python3

# Implementation of matplotlib function  
from matplotlib.axis import Axis 
import numpy as np 
import matplotlib.pyplot as plt 
    
fig, (ax1, ax2) = plt.subplots(2, 1, sharex = True) 
fig.subplots_adjust(left=0.2, wspace=0.6) 
box = dict(facecolor='green', pad=5, alpha=0.2) 
    
np.random.seed(19680801) 
ax1.plot(2*np.random.rand(10)) 
ax1.set_title('Label is not aligned') 
ax1.yaxis.set_label_text('Default', bbox=box) 
ax1.set_ylim(0, 20) 
print("Position of Label in Axes 1:", 
      ax1.yaxis.get_label_position()) 
    
ax2.set_title('\nLabel is aligned') 
ax2.plot(20*np.random.rand(10)) 
ax2.yaxis.set_label_text('Adjusted', bbox=box) 
ax2.yaxis.set_label_position('right') 
ax2.set_ylim(0, 20) 
print("Position of Label in Axes 2:", 
      ax2.yaxis.get_label_position()) 
    
fig.suptitle("Matplotlib.axis.Axis.get_label_position()\ 
Function Example", fontsize = 12, fontweight ='bold') 
  
plt.show()

輸出:

Position of Label in Axes 1:left
Position of Label in Axes 2:right




相關用法


注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Matplotlib.axis.Axis.get_label_position() function in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。