Matplotlib.axis.axis.set_ticklabels()
Python matplotlib库的Axis模块中的Axis.set_ticklabels()函数用于设置刻度标签的文本值。
Axis.set_ticklabels(self, ticklabels, *args, minor=False, **kwargs)
参数:该方法接受以下参数。
- ticklabels:这个参数是标记标签的文本列表。
- 次要:包含bool。
返回值:该方法返回文本列表。
下面的例子演示了matplotlib.axis.axis.set_ticklabels()函数在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_ticklabels(['','a','b','c','d',
'e','f','g','h','i',
''])
ax.xaxis.set_ticklabels(['','A','B','C','D',
'E','F','G',''])
ax.grid()
fig.suptitle("""matplotlib.axis.Axis.set_ticklabels()
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_ticklabels(['','A','B','C','D',
'E','F','G',''])
ax.grid()
fig.suptitle("""matplotlib.axis.Axis.set_ticklabels()
function Example\n""", fontweight ="bold")
plt.show()
输出: