Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In Python, using matplotlib, is there a way to change the distance of the dashes for different linestyles, for example, using the following command:

plt.plot(x,y,linestyle='--')
like image 729
grover Avatar asked Jan 30 '16 07:01

grover


People also ask

How do you space a dash in Python?

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

How do you change lines in Matplotlib?

The default linestyle while plotting data is solid linestyle in matplotlib. We can change this linestyle by using linestyle or ls argument of plot() method.


1 Answers

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

import matplotlib.pyplot as plt

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

lines

like image 147
gcalmettes Avatar answered Oct 23 '22 16:10

gcalmettes