python matplotlib.pyplot.xticks() yticks() (设置x或y轴对应显示的标签)

from matplotlib\pyplot.py

def xticks(ticks=None, labels=None, **kwargs):
    """
    Get or set the current tick locations and labels of the x-axis.
    获取或设置x轴的当前刻度位置和标签。

    Call signatures::

        locs, labels = xticks()            # Get locations and labels
        获取位置和标签
        xticks(ticks, [labels], **kwargs)  # Set locations and labels
        设置位置和标签

    Parameters
    ----------
    ticks : array_like
        A list of positions at which ticks should be placed. You can pass an empty list to disable xticks.
        应当放置刻度的位置列表。 您可以传递一个空列表来禁用xticks。

    labels : array_like, optional
        A list of explicit labels to place at the given *locs*.
        放置在给定* locs *处的显式标签的列表。

    **kwargs
        :class:`.Text` properties can be used to control the appearance of the labels.
        Text属性可以用来控制标签的外观。

    Returns
    -------
    locs
        An array of label locations.
    labels
        A list of `.Text` objects.

    Notes
    -----
    Calling this function with no arguments (e.g. ``xticks()``) is the pyplot equivalent of calling `~.Axes.get_xticks` and `~.Axes.get_xticklabels` on the current axes.
    Calling this function with arguments is the pyplot equivalent of calling `~.Axes.set_xticks` and  `~.Axes.set_xticklabels` on the current axes.
    pyplot等效于在当前轴上调用`〜.Axes.get_xticks`和`〜.Axes.get_xticklabels`的不带参数的函数(例如``xticks()``)。
     使用参数调用此函数的pyplot等效于在当前轴上调用〜.Axes.set_xticks和〜.Axes.set_xticklabels。

    Examples
    --------
    Get the current locations and labels:

        >>> locs, labels = xticks()

    Set label locations:

        >>> xticks(np.arange(0, 1, step=0.2))

    Set text labels:

        >>> xticks(np.arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue'))

    Set text labels and properties:

        >>> xticks(np.arange(12), calendar.month_name[1:13], rotation=20)

    Disable xticks:

        >>> xticks([])
    """

参考文章:python matplotlib Text类

发布了857 篇原创文章 · 获赞 49 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/Dontla/article/details/104513405
今日推荐