Matplotlib.axis.axis.get_offset_text() - 获取offsetText轴作为文本实例

Matplotlib.axis.axis.get_offset_text()

matplotlib库的Axis模块中的Axis.get_offset_text()函数用于获取offsetText轴作为文本实例。

语法:Axis.get_offset_text(self)

参数:该方法不接受任何参数。

返回值:该方法返回作为Text实例的offsetText轴。

下面的例子说明了matplotlib.axis.axis.get_offset_text()函数在matplotlib.axis中的作用:

示例1

# Implementation of matplotlib function 
from matplotlib.axis import Axis  
import matplotlib.pyplot as plt 
import matplotlib.text 
     
fig, ax = plt.subplots() 
     
ax.plot([5,1], label="Label 1") 
ax.plot([3,0], label="Label 2") 
     
legend = ax.legend(loc="upper right") 
offset = matplotlib.text.OffsetFrom(legend, (1.0, 0.0))
  
ax.annotate("String - Info", 
            xy = (0,0),  
            size = 14, 
            xycoords = 'figure fraction', 
            xytext = (0,-20),  
            textcoords = offset,  
            horizontalalignment = 'right',  
            verticalalignment = 'top') 
    
fig.canvas.draw() 
fig.suptitle('Matplotlib.axis.Axis.get_offset_text()\n\
Function Example')  
ax.grid()
   
print("Value of get_offset_text() :",ax.xaxis.get_offset_text())
      
plt.show()

输出:

Matplotlib.axis.axis.get_offset_text()

Value of get_offset_text() : Text(1, 24.911111111111108, '')

示例2

# Implementation of matplotlib function 
from matplotlib.axis import Axis  
import matplotlib.pyplot as plt 
import numpy as np 
    
    
fig, geeeks = plt.subplots() 
    
t = np.arange(0.0, 5.0, 0.001) 
s = np.cos(3 * np.pi * t) 
line = geeeks.plot(t, s, lw = 2) 
    
# Annotation 
geeeks.annotate('Local Max', xy =(3.3, 1), 
                xytext =(3, 1.8),  
                arrowprops = dict(facecolor ='green', 
                                  shrink = 0.05),) 
    
geeeks.set_ylim(-2, 2) 
fig.suptitle('Matplotlib.axis.Axis.get_offset_text()\n\
Function Example')  
geeeks.grid()
   
print("Value of get_offset_text() :",geeeks.xaxis.get_offset_text())
      
plt.show()

输出:

Matplotlib.axis.axis.get_offset_text()

Value of get_offset_text() : Text(1, 0, '')

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

matplotlib.axis