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


Python Matplotlib.axes.Axes.get_axes_locator()用法及代码示例


Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。轴类包含大多数图形元素:Axis,Tick,Line2D,Text,Polygon等,并设置坐标系。 Axes实例通过callbacks属性支持回调。

matplotlib.axes.Axes.get_axes_locator()函数

matplotlib库的axiss模块中的Axes.set_axes_locator()函数用于获取轴定位器。

用法: Axes.get_axes_locator(self)


返回值:此方法返回axes_locator。

以下示例说明了matplotlib.axes中的matplotlib.axes.Axes.get_axes_locator()函数:

范例1:

# Implementation of matplotlib function 
from mpl_toolkits.axes_grid1 import Size, Divider 
import matplotlib.pyplot as plt 
   
   
fig = plt.figure(1, (6, 6)) 
   
value1 = [Size.Fixed(2.),  
          Size.Fixed(.8),  
          Size.Fixed(1.2), 
          Size.Fixed(.7)] 
  
value2 = [Size.Fixed(1.2),  
          Size.Fixed(.7),  
          Size.Fixed(2.)] 
   
polygon = (0.2, 0.2, 0.4, 0.4) 
resultant = Divider(fig, polygon,  
                    value1, value2, 
                    aspect = False) 
   
ax1 = fig.add_axes(polygon, label ="2") 
ax2 = fig.add_axes(polygon, label ="3") 
ax3 = fig.add_axes(polygon, label ="1") 
ax4 = fig.add_axes(polygon, label ="4") 
   
ax1.set_axes_locator(resultant.new_locator(nx = 0, 
                                           ny = 0)) 
ax2.set_axes_locator(resultant.new_locator(nx = 0, 
                                           ny = 2)) 
ax3.set_axes_locator(resultant.new_locator(nx = 3,  
                                           ny = 2)) 
ax4.set_axes_locator(resultant.new_locator(nx = 3, 
                                           nx1 = 4,  
                                           ny = 0)) 
  
w = ax1.get_axes_locator() 
w2 = ax2.get_axes_locator() 
w3 = ax3.get_axes_locator() 
w4 = ax4.get_axes_locator() 
  
   
fig.suptitle('matplotlib.axes.Axes.get_axes_locator()\ 
function Example\n\n' 
             +str(w)+'\n'+str(w2)+'\n'+str(w3)+'\n'+str(w4)+'\n\n\n\n') 
plt.show()

输出:

范例2:

# Implementation of matplotlib function 
import numpy as np 
import matplotlib.pyplot as plt 
from mpl_toolkits.axes_grid1.axes_divider import HBoxDivider 
import mpl_toolkits.axes_grid1.axes_size as Size 
   
arr1 = np.arange(40).reshape((8, 5)) 
arr2 = np.arange(12).reshape((3, 4)) 
   
fig, (ax1, ax2) = plt.subplots(1, 2) 
ax1.imshow(arr1) 
ax2.imshow(arr2) 
   
rect = 111
pad = 1
for ax in [ax1, ax2]:
    ax.locator_params(nbins = 1) 
    ax.xaxis.set_visible(False) 
    ax.yaxis.set_visible(False) 
   
h1, v1 = Size.AxesX(ax1), Size.AxesY(ax1) 
h2, v2 = Size.AxesX(ax2), Size.AxesY(ax2) 
   
pad_v = Size.Scaled(1) 
pad_h = Size.Fixed(pad) 
   
my_divider = HBoxDivider(fig, rect, 
                         horizontal =[h1, pad_h, h2], 
                         vertical =[v1, pad_v, v2]) 
   
ax1.set_axes_locator(my_divider.new_locator(0)) 
ax2.set_axes_locator(my_divider.new_locator(2)) 
   
ax3 = plt.axes([0.4, 0.5, 0.001, 0.001], frameon = False) 
ax3.xaxis.set_visible(False) 
ax3.yaxis.set_visible(False) 
ax3.annotate("GeeksforGeeks\n matplotlib module \n Axes class", 
             (1, 0.5), 
             xycoords ="axes fraction",  
             va ="center", ha ="center", 
             bbox = dict(boxstyle ="round, pad = 1", fc ="w")) 
  
w1 = ax1.get_axes_locator() 
w2 = ax2.get_axes_locator() 
w3 = ax3.get_axes_locator() 
  
   
fig.suptitle('matplotlib.axes.Axes.get_axes_locator() \ 
function Example\n\n' 
             +str(w1)+'\n'+str(w2)+'\n'+str(w3)+'\n\n\n\n') 
plt.show()

输出:





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