79142504

Date: 2024-10-30 19:10:59
Score: 0.5
Natty:
Report link

You can set the offset explicitly in linestyle. While there's probably a way to compute the correct offsets, for simple use-cases I'd suggest just fiddling with it until it looks right.

import matplotlib.pyplot as plt
import matplotlib as mpl

plt.title("Offsets in dashed lines")
plt.show()

num_lines = 6
for i in range(num_lines):
    dash_pattern_tuple = mpl.rcParams[f'lines.dashed_pattern']  # (3.7, 1.6), meaning a 3.7pt line and a 1.6pt gap.
    cycle_pt_size = sum(dash_pattern_tuple)
    offset_fraction = i / num_lines
    offset_pt = cycle_pt_size * offset_fraction
    ax.plot((-1, 1), (i, i), linestyle=(offset_pt, (3.7, 1.6)))

Matplot plot of 6 dashed lines that are all 1/6th phase offset from each other.

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Kaia