Python中的 Matplotlib.axis.Axis.get_smart_bounds()函数
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。它是Python中用于二维数组图的惊人可视化库,用于处理更广泛的 SciPy 堆栈。
Matplotlib.axis.Axis.get_smart_bounds()函数
matplotlib库的axis模块中的axis.get_smart_bounds()函数用于获取轴是否有智能边界。
Syntax: Axis.get_smart_bounds(self)
Parameters: This method does not accepts any parameters.
Return value: This method return whether the axis has smart bounds.
下面的示例说明了 matplotlib.axis 中的 matplotlib.axis.Axis.get_smart_bounds()函数:
示例 1:
Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
x = np.linspace(-np.pi, np.pi, 100)
y = 2*np.sin(x)
ax = fig.add_subplot()
ax.set_title('centered spines')
ax.plot(x, y)
ax.spines['left'].set_position('center')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('center')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.grid()
print("Value return by get_smart_bounds() : [",
ax.xaxis.get_smart_bounds(),
ax.yaxis.get_smart_bounds(),"]")
fig.suptitle("""matplotlib.axis.Axis.get_smart_bounds()
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 = plt.figure()
x = np.linspace(-np.pi, np.pi, 100)
y = 2*np.sin(x)
ax = fig.add_subplot()
ax.set_title('Spines at data (3, 2)')
ax.plot(x, y)
ax.spines['left'].set_position(('data', 3))
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position(('data', 2))
ax.spines['top'].set_color('none')
ax.spines['left'].set_smart_bounds(True)
ax.spines['bottom'].set_smart_bounds(True)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.grid()
print("Value return by get_smart_bounds() :",
ax.xaxis.get_smart_bounds())
fig.suptitle("""matplotlib.axis.Axis.get_smart_bounds()
function Example\n""", fontweight ="bold")
plt.show()
输出:
Value return by get_smart_bounds() : [ False False ]
示例 2:
Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
x = np.linspace(-np.pi, np.pi, 100)
y = 2*np.sin(x)
ax = fig.add_subplot()
ax.set_title('Spines at data (3, 2)')
ax.plot(x, y)
ax.spines['left'].set_position(('data', 3))
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position(('data', 2))
ax.spines['top'].set_color('none')
ax.spines['left'].set_smart_bounds(True)
ax.spines['bottom'].set_smart_bounds(True)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.grid()
print("Value return by get_smart_bounds() :",
ax.xaxis.get_smart_bounds())
fig.suptitle("""matplotlib.axis.Axis.get_smart_bounds()
function Example\n""", fontweight ="bold")
plt.show()
输出:
Value return by get_smart_bounds() : True