diff --git a/examples/misc/tickedstroke_demo.py b/examples/misc/tickedstroke_demo.py index 0e4b00b7d5cb..a821c04f8149 100644 --- a/examples/misc/tickedstroke_demo.py +++ b/examples/misc/tickedstroke_demo.py @@ -13,11 +13,10 @@ draws a path with a ticked style. The spacing, length, and angle of ticks can be controlled. -See also the :doc:`contour demo example -`. +See also the :doc:`/gallery/lines_bars_and_markers/lines_with_ticks_demo` example. -See also the :doc:`contours in optimization example -`. +See also the :doc:`/gallery/images_contours_and_fields/contours_in_optimization_demo` +example. """ ############################################################################### @@ -103,3 +102,20 @@ ax.set_ylim(0, 4) plt.show() + +# %% +# Direction/side of the ticks +# =========================== +# +# To change which side of the line the ticks are drawn, change the sign of the angle. + +fig, ax = plt.subplots(figsize=(6, 6)) +line_x = line_y = [0, 1] +ax.plot(line_x, line_y, label="Line", + path_effects=[patheffects.withTickedStroke(spacing=7, angle=135)]) + +ax.plot(line_x, line_y, label="Opposite side", + path_effects=[patheffects.withTickedStroke(spacing=7, angle=-135)]) + +ax.legend() +plt.show() diff --git a/lib/matplotlib/patheffects.py b/lib/matplotlib/patheffects.py index 191f62b8d2be..4b4d923783df 100644 --- a/lib/matplotlib/patheffects.py +++ b/lib/matplotlib/patheffects.py @@ -386,11 +386,7 @@ class TickedStroke(AbstractPathEffect): This line style is sometimes referred to as a hatched line. - See also the :doc:`contour demo example - `. - - See also the :doc:`contours in optimization example - `. + See also the :doc:`/gallery/misc/tickedstroke_demo` example. """ def __init__(self, offset=(0, 0), @@ -407,7 +403,8 @@ def __init__(self, offset=(0, 0), The angle between the path and the tick in degrees. The angle is measured as if you were an ant walking along the curve, with zero degrees pointing directly ahead, 90 to your left, -90 - to your right, and 180 behind you. + to your right, and 180 behind you. To change side of the ticks, + change sign of the angle. length : float, default: 1.414 The length of the tick relative to spacing. Recommended length = 1.414 (sqrt(2)) when angle=45, length=1.0