Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DOC] Clarify how to change side of the TickedStroke ticks #25394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions galleries/examples/misc/tickedstroke_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
</gallery/lines_bars_and_markers/lines_with_ticks_demo>`.
See also the :doc:`/gallery/lines_bars_and_markers/lines_with_ticks_demo` example.

See also the :doc:`contours in optimization example
</gallery/images_contours_and_fields/contours_in_optimization_demo>`.
See also the :doc:`/gallery/images_contours_and_fields/contours_in_optimization_demo`
example.
"""

import matplotlib.pyplot as plt
Expand Down Expand Up @@ -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()
9 changes: 3 additions & 6 deletions lib/matplotlib/patheffects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
</gallery/lines_bars_and_markers/lines_with_ticks_demo>`.

See also the :doc:`contours in optimization example
</gallery/images_contours_and_fields/contours_in_optimization_demo>`.
See also the :doc:`/gallery/misc/tickedstroke_demo` example.
"""

def __init__(self, offset=(0, 0),
Expand All @@ -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
Expand Down