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

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

Python中的 Matplotlib.axis.Axis.limit_range_for_scale()函数

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

Matplotlib.axis.Axis.limit_range_for_scale()函数

matplotlib 库的轴模块中的Axis.limit_range_for_scale()函数用于重新初始化主要和次要 Tick 列表。

下面的示例说明了 matplotlib.axis 中的 matplotlib.axis.Axis.limit_range_for_scale()函数:

示例 1:

Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
   
fig, ax = plt.subplots()
   
ax.set_yscale("log")
ax.set_adjustable("datalim")
ax.plot([1, 3, 10], [1, 9, 100], "o-",color="green")
ax.set_aspect(1)
  
ax.xaxis.limit_range_for_scale(0,5)
   
ax.grid() 
   
fig.suptitle("""matplotlib.axis.Axis.limit_range_for_scale()
function Example\n""", fontweight ="bold")  
     
plt.show()


Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
import numpy as np
import matplotlib.pyplot as plt
   
   
fig, ax4 = plt.subplots()
   
x = 10.0**np.linspace(0.0, 2.0, 15)
y = x**2.0
ax4.set_xscale("log", nonposx='clip')
ax4.set_yscale("log", nonposy='clip')
   
ax4.errorbar(x, y, xerr=0.1 * x, 
             yerr=2.0 + 1.75 * y,
             color="green")
   
ax4.set_ylim(bottom=0.1)
  
ax4.xaxis.limit_range_for_scale(0,5)
ax4.yaxis.limit_range_for_scale(3,5)
   
ax4.grid() 
   
fig.suptitle("""matplotlib.axis.Axis.limit_range_for_scale()
function Example\n""", 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, ax4 = plt.subplots()
   
x = 10.0**np.linspace(0.0, 2.0, 15)
y = x**2.0
ax4.set_xscale("log", nonposx='clip')
ax4.set_yscale("log", nonposy='clip')
   
ax4.errorbar(x, y, xerr=0.1 * x, 
             yerr=2.0 + 1.75 * y,
             color="green")
   
ax4.set_ylim(bottom=0.1)
  
ax4.xaxis.limit_range_for_scale(0,5)
ax4.yaxis.limit_range_for_scale(3,5)
   
ax4.grid() 
   
fig.suptitle("""matplotlib.axis.Axis.limit_range_for_scale()
function Example\n""", fontweight ="bold")  
     
plt.show()

输出: