Получение осей x и y со стрелками в matplotlib и управление положением меток x и y - PullRequest
0 голосов
/ 06 июня 2019

Привет график, приведенный здесь https://matplotlib.org/examples/axes_grid/demo_axisline_style.html

имеет метки на оси Y на правой стороне оси Y, но я хочу, чтобы они были на левой стороне оси Y,Как мне это сделать?

from mpl_toolkits.axes_grid.axislines import SubplotZero
from matplotlib.transforms import BlendedGenericTransform
import matplotlib.pyplot as plt
import numpy

if 1:
    fig = plt.figure(1)
    ax = SubplotZero(fig, 111)
    fig.add_subplot(ax)

    ax.axhline(linewidth=1.7, color="black")
    ax.axvline(linewidth=1.7, color="black")

    plt.xticks(range(11))

    ax.text(0, 1.05, 'y', transform=BlendedGenericTransform(ax.transData, ax.transAxes), ha='center')
    ax.text(1.05, 0, 'x', transform=BlendedGenericTransform(ax.transAxes, ax.transData), va='center')

    for direction in ["xzero", "yzero"]:
        ax.axis[direction].set_axisline_style("-|>")
        ax.axis[direction].set_visible(True)

    ax.axis["yzero"].set_visible(False)

    for direction in ["right", "top"]:
        ax.axis[direction].set_visible(False)

    plt.yticks(range(11))
    plt.grid(True)

    plt.show()

Этот блок кода дает мне это.Но стрелка от оси Y отсутствует.

1 Ответ

3 голосов
/ 06 июня 2019

Добавлено 2 строки в вашем коде.Надеюсь, что это поможет.

  1. добавлено для инвертирования метки справа налево.

    ax.axis["yzero"].invert_ticklabel_direction()
    
  2. установите 'left', чтобы быть невидимым

    for direction in ["left", "right", "top"]: 
    

Обновлено в вашем коде:

    from mpl_toolkits.axisartist.axislines import SubplotZero
    from matplotlib.transforms import BlendedGenericTransform
    import matplotlib.pyplot as plt
    import numpy

    if 1:
        fig = plt.figure(1)
        ax = SubplotZero(fig, 111)
        fig.add_subplot(ax)

        ax.axhline(linewidth=1.7, color="black")
        ax.axvline(linewidth=1.7, color="black")

        plt.xticks(range(11))

        ax.text(0, 1.05, 'y', transform=BlendedGenericTransform(ax.transData, ax.transAxes), ha='center')
        ax.text(1.05, 0, 'x', transform=BlendedGenericTransform(ax.transAxes, ax.transData), va='center')

        for direction in ["xzero", "yzero"]:
            ax.axis[direction].set_axisline_style("-|>")
            ax.axis[direction].set_visible(True)

        # added to invert the label from right to left.
        ax.axis["yzero"].invert_ticklabel_direction()

        # set 'left' to be invisible
        for direction in ["left", "right", "top"]:  # for direction in ["right", "top"]:
            ax.axis[direction].set_visible(False)

        plt.yticks(range(11))
        plt.grid(True)

        plt.show()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...