Python中的 Matplotlib.axis.Tick.have_units()函数
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。它是Python中用于二维数组图的惊人可视化库,用于处理更广泛的 SciPy 堆栈。
Matplotlib.axis.Tick.have_units()函数
matplotlib 库的轴模块中的Tick.have_units()函数用于检查单位是否设置在任何轴上。
Syntax: Tick.have_units(self)
Parameters: This method does not accepts any parameter.
Return value: This method return True if units are set on any axis.
以下示例说明了 matplotlib.axis 中的 matplotlib.axis.Tick.have_units()函数:
示例 1:
Python3
# Implementation of matplotlib function
from matplotlib.axis import Tick
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Ellipse
delta = 15.0
angles = np.arange(0, 360 + delta, delta)
ells = [Ellipse((2, 2), 5, 2, a) for a in angles]
fig, ax = plt.subplots()
for e in ells:
Tick.set_clip_box(e, ax.bbox)
e.set_facecolor("green")
e.set_alpha(0.05)
ax.add_artist(e)
plt.xlim(-1, 5)
plt.ylim(-1, 5)
ax.set_title("Units are set on any axis : "
+str(Tick.have_units(ax.xaxis)))
fig.suptitle('matplotlib.axis.Tick.have_units() \
function Example', fontweight ="bold")
plt.show()
Python3
# Implementation of matplotlib function
from matplotlib.axis import Tick
import matplotlib.pyplot as plt
fig, ax1 = plt.subplots( )
ax1.set_xscale("log")
ax1.set_yscale("log")
ax1.set_adjustable("datalim")
ax1.plot([1, 3, 34, 4, 46, 3, 7, 45, 10],
[1, 9, 27, 8, 29, 84, 78, 19, 48],
"o-", color ="green")
ax1.set_xlim(1e-1, 1e2)
ax1.set_ylim(1, 1e2)
w = Tick.have_units(ax1.yaxis)
print("Value Return by have_units() :", w)
fig.suptitle('matplotlib.axis.Tick.have_units() \
function Example', fontweight ="bold")
plt.show()
输出:
示例 2:
Python3
# Implementation of matplotlib function
from matplotlib.axis import Tick
import matplotlib.pyplot as plt
fig, ax1 = plt.subplots( )
ax1.set_xscale("log")
ax1.set_yscale("log")
ax1.set_adjustable("datalim")
ax1.plot([1, 3, 34, 4, 46, 3, 7, 45, 10],
[1, 9, 27, 8, 29, 84, 78, 19, 48],
"o-", color ="green")
ax1.set_xlim(1e-1, 1e2)
ax1.set_ylim(1, 1e2)
w = Tick.have_units(ax1.yaxis)
print("Value Return by have_units() :", w)
fig.suptitle('matplotlib.axis.Tick.have_units() \
function Example', fontweight ="bold")
plt.show()
输出:
Value Return by have_units() : False