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)))