Matplotlib.axis.axis.reset_ticks()
Python matplotlib库的Axis模块中的Axis.reset_ticks()函数用于重新初始化主刻度表和次刻度表。
语法:Axis.reset_ticks(self)
参数:该方法不接受任何参数。
返回值:该方法不返回任何值。
下面的例子演示了matplotlib.axis.axis.reset_ticks()函数在matplotlib.axis中的作用:
示例1
# 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()
输出:
示例2
# 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()
输出: