Active 02 décembre 2014    /    Viewed 13552    /    Comments 0    /    Edit

Exemples de comment tracer une ligne pointillée avec matplotlib:

### Tracer une ligne pointillée

Avec matplotlib il est possible de tracer des lignes en pointillée en ajoutant l'argument '--' ou ':' ou '-:', exemple:

````import matplotlib.pyplot as plt`

`x = [1,10]`
`y = [3,6]`

`plt.plot(x,y,'--')`

`plt.savefig('DashedLine_01.png')`
`plt.show()`
```

````import matplotlib.pyplot as plt`

`x = [1,10]`
`y = [3,6]`

`plt.plot(x,y,':')`

`plt.savefig('DashedLine_02.png')`
`plt.show()`
```

````import matplotlib.pyplot as plt`

`x = [1,10]`
`y = [3,6]`

`plt.plot(x,y,'-.')`

`plt.savefig('DashedLine_03.png')`
`plt.show()`
```

### Personnaliser la ligne pointillée

Il est aussi possible de créer sa propre ligne pointillée avec une mise en forme quelconque voir:

````import matplotlib.pyplot as plt`

`x = [1,10]`
`y = [3,6]`

`dashes = [5,2,10,5] # 5 points on, 2 off, 3 on, 1 off`

`l, = plt.plot(x,y, '--')`

`l.set_dashes(dashes)`

`plt.title('How to plot a dashed line in matplotlib ?', fontsize=7)`

`plt.savefig("dashed_line.png", bbox_inches='tight')`

`plt.show()`
```

### Références

Liens Site
plot matplotlib doc
pylab_examples example code: dash_control.py matplotlib doc
python matplotlib dash-dot-dot - how to? stackoverflow
A simple plot with a custom dashed line matplotlib doc

##### Daidalos

Hi, I am Ben.

I have developed this web site from scratch with Django to share with everyone my notes. If you have any ideas or suggestions to improve the site, let me know ! (you can contact me using the form in the welcome page). Thanks!

Did you find this content useful ?, If so, please consider donating a tip to the author(s). MoonBooks.org is visited by millions of people each year and it will help us to maintain our servers and create new contents.

Amount