Line charts work out of the box with matplotlib. You can have multiple lines in a line chart, change color, change type of line and much more.

Matplotlib is a Python module for plotting. Line charts are one of the many chart types it can create.

Related course: Matplotlib Examples and Video Course

## Line chart examples

### Line chart

First import matplotlib and numpy, these are useful for charting.
You can use the plot(x,y) method to create a line chart.

### Curved line

The plot() method also works for other types of line charts. It doesn’t need to be a straight line, y can have any type of values.

### Line with Labels

To know what you are looking at, you need meta data. Labels are a type of meta data. They show what the chart is about. The chart has an x label, y label and title.

### Multiple lines

More than one line can be in the plot. To add another line, just call the plot(x,y) function again. In the example below we have two different values for y (y1,y2) that are plotted onto the chart.

### Dotted line

Lines can be in the form of dots like the image below. Instead of calling plot(x,y) call the scatter(x,y) method. The scatter(x,y) method can also be used to (randomly) plot points onto the chart.

### Line ticks

You can change the ticks on the plot. Set them on the x-axis, y-axis or even change their color. The line can be more thick and have an alpha value.

### Line with asymptote

An asymptote can be added to the plot. To do that, use plt.annotate(). There’s lso a dotted line in the plot below. You can play around with the code to see how it works.

### Line with text scale

It doesn’t have to be a numeric scale. The scale can also contain textual words like the example below. In plt.yticks() we just pass a list with text values. These values are then show against the y axis.

If you are new to matplotlib, then I highly recommend this course.