Matplotlib Line
Learn all about Matplotlib Line in this comprehensive tutorial.
- •You can use the keyword argument linestyle, or shorter ls, to change the style of the plotted line:
- •The line style can be written in a shorter syntax:
- •You can choose any of these styles:
- •You can use the keyword argument color or the shorter c to set the color of the line:
- •You can use the keyword argument linewidth or the shorter lw to change the width of the line.
- •You can plot as many lines as you like by simply adding more plt.
Linestyle
You can use the keyword argument linestyle, or shorter ls, to change the style of the plotted line:
Shorter Syntax
The line style can be written in a shorter syntax:
linestyle can be written as ls.
dotted can be written as :.
dashed can be written as --.
Line Styles
You can choose any of these styles:
| Style | Or | |
|---|---|---|
| 'solid' (default) | '-' | Try it » |
| 'dotted' | ':' | Try it » |
| 'dashed' | '--' | Try it » |
| 'dashdot' | '-.' | Try it » |
| 'None' | '' or ' ' | Try it » |
Line Color
You can use the keyword argument color or the shorter c to set the color of the line:
You can also use Hexadecimal color values:
Or any of the 140 supported color names.
Line Width
You can use the keyword argument linewidth or the shorter lw to change the width of the line.
The value is a floating number, in points:
Multiple Lines
You can plot as many lines as you like by simply adding more plt.plot() functions:
You can also plot many lines by adding the points for the x- and y-axis for each line in the same plt.plot() function.
(In the examples above we only specified the points on the y-axis, meaning that the points on the x-axis got the the default values (0, 1, 2, 3).)
The x- and y- values come in pairs:
Module quiz
2 questionsWhich of the following is true about Matplotlib Line?
What is the most common pitfall when working with Matplotlib Line?
Answer all questions to submit.