📌  相关文章
📜  Python中的 Matplotlib.axes.Axes.locator_params()

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

Python中的 Matplotlib.axes.Axes.locator_params()

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

matplotlib.axes.Axes.locator_params()函数

matplotlib 库的 axes 模块中的Axes.locator_params()函数用于控制主要刻度定位器的行为。

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

示例 1:

# Implementation of matplotlib function
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.gridspec as gridspec
import numpy as np
   
   
plt.rcParams['savefig.facecolor'] = "0.8"
plt.rcParams['figure.figsize'] = 6, 5
   
fig, ax = plt.subplots()
   
ax.plot([1, 2])
   
ax.locator_params("x", nbins = 3)
ax.locator_params("y", nbins = 5)
   
ax.set_xlabel('x-label')
ax.set_ylabel('y-label')
   
fig.suptitle('matplotlib.axes.Axes.locator_params() \
function Example\n\n', fontweight ="bold")
plt.show()

输出:

示例 2:

# Implementation of matplotlib function
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.gridspec as gridspec
import numpy as np
  
  
arr = np.arange(100).reshape((10, 10))
norm = mcolors.Normalize(vmin = 0., vmax = 100.)
  
pc_kwargs = {'rasterized': True, 'cmap': 'viridis',
             'norm': norm}
  
fig, (ax, ax1) = plt.subplots(1, 2)
  
im = ax.pcolormesh(arr, **pc_kwargs)
fig.colorbar(im, ax = ax, shrink = 0.6)
  
im1 = ax1.pcolormesh(arr, **pc_kwargs)
ax1.locator_params(nbins = 3)
fig.colorbar(im1, ax = ax1, shrink = 0.6)
  
ax.set_title("Without locator_params()")
ax1.set_title("With locator_params()")
  
fig.suptitle('matplotlib.axes.Axes.locator_params() \
function Example\n\n', fontweight ="bold")
plt.show()

输出: