Python中的 Matplotlib.axis.Axis.remove_overlapping_locs()函数
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。它是Python中用于二维数组图的惊人可视化库,用于处理更广泛的 SciPy 堆栈。
Matplotlib.axis.Axis.remove_overlapping_locs函数
matplotlib 库的轴模块中的Axis.remove_overlapping_locs函数用于修剪与主要代码位置重叠的次要代码位置。
Syntax: Axis.remove_overlapping_locs
Parameters: This method accepts the following parameters.
- formatter: This parameter is the locator.
Return value: This method does not returns any value.
下面的示例说明了 matplotlib.axis 中的 matplotlib.axis.Axis.remove_overlapping_locs函数:
示例 1:
Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, ScalarFormatter
fig, ax = plt.subplots()
ax.plot([0, 5, 10, 15, 20], [3, 2, 1, 2, 4])
Axis.set_minor_locator(ax.xaxis, MultipleLocator(1))
Axis.set_minor_formatter(ax.xaxis, ScalarFormatter())
Axis.set_major_locator(ax.xaxis, MultipleLocator(4))
ax.tick_params(axis ='both', which ='major',
labelsize = 14, pad = 12,
colors ='g')
ax.tick_params(axis ='both', which ='minor',
labelsize = 8, colors ='b')
ax.xaxis.remove_overlapping_locs
plt.title("Matplotlib.axis.Axis.remove_overlapping_locs \
Example", fontsize = 12, fontweight ='bold')
plt.show()
Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from matplotlib.ticker import MultipleLocator, ScalarFormatter
x = [0, 5, 9, 10, 15]
y = [0, 1, 2, 3, 4]
tick_spacing = 1
fig, ax = plt.subplots(1, 1)
ax.plot(x, y)
Axis.set_major_locator(ax.xaxis,
ticker.MultipleLocator(3))
Axis.set_minor_locator(ax.xaxis,
ticker.MultipleLocator(tick_spacing))
Axis.set_minor_formatter(ax.xaxis, ScalarFormatter())
ax.xaxis.remove_overlapping_locs
plt.title("Matplotlib.axis.Axis.remove_overlapping_locs \
Example", fontsize = 12, fontweight ='bold')
plt.show()
输出:
示例 2:
Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from matplotlib.ticker import MultipleLocator, ScalarFormatter
x = [0, 5, 9, 10, 15]
y = [0, 1, 2, 3, 4]
tick_spacing = 1
fig, ax = plt.subplots(1, 1)
ax.plot(x, y)
Axis.set_major_locator(ax.xaxis,
ticker.MultipleLocator(3))
Axis.set_minor_locator(ax.xaxis,
ticker.MultipleLocator(tick_spacing))
Axis.set_minor_formatter(ax.xaxis, ScalarFormatter())
ax.xaxis.remove_overlapping_locs
plt.title("Matplotlib.axis.Axis.remove_overlapping_locs \
Example", fontsize = 12, fontweight ='bold')
plt.show()
输出: