Python中的 Matplotlib.axis.Axis.reset_ticks()函数
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。它是Python中用于二维数组图的惊人可视化库,用于处理更广泛的 SciPy 堆栈。
Matplotlib.axis.Axis.reset_ticks()函数
matplotlib 库的轴模块中的Axis.reset_ticks()函数用于重新初始化主要和次要 Tick 列表。
Syntax: Axis.reset_ticks(self)
Parameters: This method does not accepts any parameter.
Return value: This method does not return any value.
下面的示例说明了 matplotlib.axis 中的 matplotlib.axis.Axis.reset_ticks()函数:
示例 1:
Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
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')
ax.yaxis.reset_ticks()
ax.grid()
fig.suptitle("""matplotlib.axis.Axis.reset_ticks()
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
import matplotlib.transforms as mtransforms
delta = 0.5
x = y = np.arange(-2.0, 4.0, delta)
X, Y = np.meshgrid(x**2, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2)
transform = mtransforms.Affine2D().rotate_deg(30)
fig, ax = plt.subplots()
im = ax.imshow(Z, interpolation ='none',
origin ='lower',
extent =[-2, 4, -3, 2],
clip_on = True)
trans_data = transform + ax.transData
Axis.set_transform(im, trans_data)
x1, x2, y1, y2 = im.get_extent()
ax.plot([x1, x2, x2, x1, x1],
[y1, y1, y2, y2, y1],
"ro-",
transform = trans_data)
ax.set_xlim(-5, 5)
ax.set_ylim(-4, 4)
ax.yaxis.reset_ticks()
ax.grid()
fig.suptitle("""matplotlib.axis.Axis.reset_ticks()
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
import matplotlib.transforms as mtransforms
delta = 0.5
x = y = np.arange(-2.0, 4.0, delta)
X, Y = np.meshgrid(x**2, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2)
transform = mtransforms.Affine2D().rotate_deg(30)
fig, ax = plt.subplots()
im = ax.imshow(Z, interpolation ='none',
origin ='lower',
extent =[-2, 4, -3, 2],
clip_on = True)
trans_data = transform + ax.transData
Axis.set_transform(im, trans_data)
x1, x2, y1, y2 = im.get_extent()
ax.plot([x1, x2, x2, x1, x1],
[y1, y1, y2, y2, y1],
"ro-",
transform = trans_data)
ax.set_xlim(-5, 5)
ax.set_ylim(-4, 4)
ax.yaxis.reset_ticks()
ax.grid()
fig.suptitle("""matplotlib.axis.Axis.reset_ticks()
function Example\n""", fontweight ="bold")
plt.show()
输出: