パスエフェクトがチェックされた行#

を使用して、ラインに沿って目盛りを追加して、片側をバリアとしてマークすることができます TickedStroke。目盛りの角度、間隔、長さを制御できます。

目盛りも凡例に適切に表示されます。

目盛り付きの行のデモ
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import patheffects

# Plot a straight diagonal line with ticked style path
fig, ax = plt.subplots(figsize=(6, 6))
ax.plot([0, 1], [0, 1], label="Line",
        path_effects=[patheffects.withTickedStroke(spacing=7, angle=135)])

# Plot a curved line with ticked style path
nx = 101
x = np.linspace(0.0, 1.0, nx)
y = 0.3*np.sin(x*8) + 0.4
ax.plot(x, y, label="Curve", path_effects=[patheffects.withTickedStroke()])

ax.legend()

plt.show()

Sphinx-Gallery によって生成されたギャラリー