Python中的 Matplotlib.pyplot.xticks()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Pyplot是Matplotlib模块的基于状态的接口,它提供了一个类似 MATLAB 的接口。
matplotlib.pyplot.xticks()函数
matplotlib 库的 pyplot 模块中的annotate()函数用于获取和设置当前刻度位置和 x 轴的标签。
Syntax:
Parameters: This method accept the following parameters that are described below:
- ticks: This parameter is the list of xtick locations. and an optional parameter. If an empty list is passed as an argument then it will removes all xticks
- labels: This parameter contains labels to place at the given ticks locations. And it is an optional parameter.
- **kwargs: This parameter is Text properties that is used to control the appearance of the labels.
Returns: This returns the following:
- locs :This returns the list of ytick locations.
- labels :This returns the list of ylabel Text objects.
结果是(locs,labels)
下面的示例说明了 matplotlib.pyplot 中的 matplotlib.pyplot.xticks()函数:
示例 #1:
matplotlib.pyplot.xticks(ticks=None, labels=None, **kwargs)
输出:
示例 #2:
# Implementation of matplotlib.pyplot.xticks()
# function
import numpy as np
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [95, 38, 54, 35]
labels = ['Geeks1', 'Geeks2', 'Geeks3', 'Geeks4']
plt.plot(x, y)
# You can specify a rotation for the tick
# labels in degrees or with keywords.
plt.xticks(x, labels, rotation ='vertical')
# Pad margins so that markers don't get
# clipped by the axes
plt.margins(0.2)
# Tweak spacing to prevent clipping of tick-labels
plt.subplots_adjust(bottom = 0.15)
plt.show()
输出: