📌  相关文章
📜  Python中的 Matplotlib.axis.Tick.set_label()函数

📅  最后修改于: 2022-05-13 01:54:58.949000             🧑  作者: Mango

Python中的 Matplotlib.axis.Tick.set_label()函数

Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。它是Python中用于二维数组图的惊人可视化库,用于处理更广泛的 SciPy 堆栈。

Matplotlib.axis.Tick.set_label()函数

matplotlib 库的axis 模块中的Tick.set_label()函数用于设置将在图例中显示的标签。

下面的示例说明了 matplotlib.axis 中的 matplotlib.axis.Tick.set_label()函数:
示例 1:

Python3
# Implementation of matplotlib function
from matplotlib.axis import Tick
import matplotlib.pyplot as plt  
import numpy as np  
from matplotlib.collections import EllipseCollection  
        
x = np.arange(5)  
y = np.arange(7)  
X, Y = np.meshgrid(x**2, y**3)  
        
XY = np.column_stack((X.ravel(), Y.ravel()))  
        
fig, ax = plt.subplots()  
        
ec = EllipseCollection(5, 7, 5, units ='y',  
                       offsets = XY * 0.5,  
                       transOffset = ax.transData,  
                       cmap ="plasma")  
       
ec.set_array((X * Y + X * X).ravel())  
       
ax.add_collection(ec)  
ax.autoscale_view()  
       
ax.set_xlabel('X')  
ax.set_ylabel('y')  
       
cbar = plt.colorbar(ec)  
cbar.set_label('X + Y')
  
fig.suptitle('matplotlib.axis.Tick.set_label() \
function Example', fontweight ="bold")  
     
plt.show()


Python3
# Implementation of matplotlib function
from matplotlib.axis import Tick
import matplotlib.pyplot as plt  
import numpy as np  
        
np.random.seed(19680801)  
        
n = 100000
x = np.random.standard_normal(n)  
y = 2 * np.random.standard_normal(n)  
z =[1, 2, 3, 4]  
        
fig, ax = plt.subplots()  
hb = ax.hexbin(x, y, 
               gridsize = 50, 
               bins ='log', 
               cmap ='inferno')    
       
cb = fig.colorbar(hb, ax = ax)  
cb.set_label('log')
  
fig.suptitle('matplotlib.axis.Tick.set_label() \
function Example', fontweight ="bold")  
     
plt.show()


输出:

示例 2:

Python3

# Implementation of matplotlib function
from matplotlib.axis import Tick
import matplotlib.pyplot as plt  
import numpy as np  
        
np.random.seed(19680801)  
        
n = 100000
x = np.random.standard_normal(n)  
y = 2 * np.random.standard_normal(n)  
z =[1, 2, 3, 4]  
        
fig, ax = plt.subplots()  
hb = ax.hexbin(x, y, 
               gridsize = 50, 
               bins ='log', 
               cmap ='inferno')    
       
cb = fig.colorbar(hb, ax = ax)  
cb.set_label('log')
  
fig.suptitle('matplotlib.axis.Tick.set_label() \
function Example', fontweight ="bold")  
     
plt.show() 

输出: