当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python Matplotlib.axis.Tick.set_label()用法及代码示例


Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。它是Python中令人惊叹的可视化库,用于数组的2D图,并用于与更广泛的SciPy堆栈配合使用。

Matplotlib.axis.Tick.set_label()函数

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

用法: Tick.set_label(self, a) 

参数:此方法接受以下参数。

  • a:通过调用str,此参数将转换为字符串。

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



以下示例说明了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() 

输出:

范例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() 

输出:




相关用法


注:本文由纯净天空筛选整理自SHUBHAMSINGH10大神的英文原创作品 Matplotlib.axis.Tick.set_label() function in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。