Python中的 Matplotlib.axis.Axis.set_ticklabels()函数
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。它是Python中用于二维数组图的惊人可视化库,用于处理更广泛的 SciPy 堆栈。
Matplotlib.axis.Axis.set_ticklabels()函数
matplotlib 库的轴模块中的Axis.set_ticklabels()函数用于设置刻度标签的文本值。
Syntax: Axis.set_ticklabels(self, ticklabels, \*args, minor=False, \*\*kwargs)
Parameters: This method accepts the following parameters.
- ticklabels : This parameter is the List of texts for tick labels.
- minor : This parameter contains the bool value.
Return value: This method returns the list of Texts.
下面的示例说明了 matplotlib.axis 中的 matplotlib.axis.Axis.set_ticklabels()函数:
示例 1:
Python3
# 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()
Python3
# 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()
输出:
示例 2:
Python3
# 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()
输出: