Matplotlib

Customizing line appearance

In this lesson, you will learn how to change the appearance of the plot lines.


Let's generate some random data with NumPy and plot it:

Python
Output
example plot

Just by default, the figures generated by matplotlib look pretty nice.

Nevertheless, matplotlib offers countless customization options.

Let's take advantage of this and adjust the look of our line:

Python
Output
example plot

Here, we have changed the style, color, and width of the line.

The linestyle argument accepts specific values, which can either be symbols or descriptive names of the style:

Python

Instead of specifying linestyle as an argument, you can also simply type ls. For instance:

Python
Output
example plot

You can even hightlight individual data points with markers using the marker argument:

Python
Output
example plot

There are various possible markers that you can add.

Here are some of the most common ones:

Python

Great! Now you know many ways to adjust the appearance of the line.