轴线样式#

此示例显示轴样式的一些配置。

注意:对于新用户来说,mpl_toolkits.axisartist Axes 类可能会令人困惑。如果唯一的目标是在轴的末端获得箭头,请查看带有箭头的居中脊柱示例。

demo axisline style
import matplotlib.pyplot as plt
import numpy as np

from mpl_toolkits.axisartist.axislines import AxesZero

fig = plt.figure()
ax = fig.add_subplot(axes_class=AxesZero)

for direction in ["xzero", "yzero"]:
    # adds arrows at the ends of each axis
    ax.axis[direction].set_axisline_style("-|>")

    # adds X and Y-axis from the origin
    ax.axis[direction].set_visible(True)

for direction in ["left", "right", "bottom", "top"]:
    # hides borders
    ax.axis[direction].set_visible(False)

x = np.linspace(-0.5, 1., 100)
ax.plot(x, np.sin(x*np.pi))

plt.show()

由 Sphinx-Gallery 生成的图库