From c98896b6e27f5fd26eadd4957d76a0d823a003e3 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sun, 5 Mar 2023 18:55:16 +0100 Subject: [PATCH] Clarify how to change side of the TickedStroke ticks --- galleries/examples/misc/tickedstroke_demo.py | 24 ++++++++++++++++---- lib/matplotlib/patheffects.py | 9 +++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/galleries/examples/misc/tickedstroke_demo.py b/galleries/examples/misc/tickedstroke_demo.py index 2cdc4593e3b0..9dbe77025d92 100644 --- a/galleries/examples/misc/tickedstroke_demo.py +++ b/galleries/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. """ import matplotlib.pyplot as plt @@ -104,3 +103,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 17bf3737b75e..3325fe03d805 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