Change spacing of dashes in dashed line in matplotlib [duplicate] Change spacing of dashes in dashed line in matplotlib [duplicate] python python

Change spacing of dashes in dashed line in matplotlib [duplicate]


You can directly specify the dashes length/space using the dashes=(length, interval space) argument inside the plot command.

import matplotlib.pyplot as pltfig,ax = plt.subplots()ax.plot([0, 1], [0, 1], linestyle='--', dashes=(5, 1)) #length of 5, space of 1ax.plot([0, 1], [0, 2], linestyle='--', dashes=(5, 5)) #length of 5, space of 5ax.plot([0, 1], [0, 3], linestyle='--', dashes=(5, 10)) #length of 5, space of 10ax.plot([0, 1], [0, 4], linestyle='--', dashes=(5, 20)) #length of 5, space of 20

lines