Matplotlib.axis.axis.set_ticks()
Python matplotlib库的Axis模块中的Axis.set_ticks()函数用于从序列刻度中设置刻度标记的位置。
Axis.set_ticks(self, ticks, \*, minor=False)
参数:该方法接受以下参数。
- ticks:该参数是浮点数的顺序。
- 次要:包含bool。
返回值:该方法不返回任何值。
下面的例子演示了matplotlib.axis.axis.set_ticks()函数在matplotlib.axis中的作用:
示例1
# Implementation of matplotlib function
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
x = np.linspace(0,2*np.pi,100)
y = 2*np.sin(x)
ax = fig.add_subplot()
ax.plot(x,y)
ax.yaxis.set_ticks([1,2,3,4,5,6,7])
ax.grid()
fig.suptitle("""matplotlib.axis.Axis.set_ticks()
function Example\n""", fontweight ="bold")
plt.show()
输出:
示例2
# Implementation of matplotlib function
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
x = np.linspace(-np.pi, np.pi, 100)
y = 2 * np.sin(x)
ax = fig.add_subplot()
ax.set_title('centered spines')
ax.plot(x, y)
ax.spines['left'].set_position('center')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('center')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks([-3, -2.5, -2, -1.5, -1,
-0.5, 0, 0.5, 1, 1.5,
2, 2.5, 3])
ax.grid()
fig.suptitle("""matplotlib.axis.Axis.set_ticks()
function Example\n""", fontweight ="bold")
plt.show()
输出: