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


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

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

Matplotlib.axis.Axis.set_label_coords()函數

matplotlib庫的軸模塊中的Axis.set_label_coords()函數用於設置標簽的坐標。

用法: Axis.set_label_coords(self, x, y, transform=None)

參數:此方法接受以下參數。

  • x,y:這些參數是標簽的坐標。

返回值:此方法不返回任何值。



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

範例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.set_xlabel('X - Label', bbox=box) 
ax2.set_xlim(0, 10) 
Axis.set_label_coords(ax2.xaxis, 0.5, 0.95) 
  
fig.suptitle("Matplotlib.axis.Axis.set_label_coords()\ 
Function Example", fontsize = 12, fontweight ='bold')  
  
plt.show()

輸出:

範例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.set_ylabel('Default', bbox=box) 
ax1.set_ylim(0, 20) 
  
ax2.set_title('\nLabel is aligned') 
ax2.plot(20*np.random.rand(10)) 
ax2.set_ylabel('Adjusted', bbox=box) 
ax2.set_ylim(0, 20) 
Axis.set_label_coords(ax2.yaxis,1.1, 0.5) 
  
fig.suptitle("Matplotlib.axis.Axis.set_label_coords()\ 
Function Example", fontsize = 12, fontweight ='bold')  
  
plt.show()

輸出:




相關用法


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