How to Change the Line Width of a Graph Plot in Matplotlib with Python? (original) (raw)

Last Updated : 12 Nov, 2020

Prerequisite : Matplotlib

In this article we will learn how to Change the Line Width of a Graph Plot in Matplotlib with Python. For that one must be familiar with the given concepts:

Approach

Example 1:

Python3 `

importing packages

import matplotlib.pyplot as plt import numpy as np

create data

x_values = np.arange(0, 10) y_values = np.arange(0, 10)

Adjust the line widths

plt.plot(x_values, y_values - 2, linewidth=5) plt.plot(x_values, y_values) plt.plot(x_values, y_values + 2, lw=5)

add legends and show

plt.legend(['Lw = 5', 'Lw = auto', 'Lw = 5']) plt.show()

`

Output :

Example 2 :

Python3 `

importing packages

import matplotlib.pyplot as plt import numpy as np

create data

x_values = np.linspace(0, 10, 1000) y_values = np.sin(x_values)

Adjust the line widths

for i in range(20): plt.plot(x_values, y_values + i0.5, lw=i0.5)

plt.show()

`

Output :

Example 3 :

Python3 `

importing packages

import matplotlib.pyplot as plt import numpy as np

create data

x_values = np.linspace(0, 10, 1000)

Adjust the line widths

for i in range(20): plt.plot(x_values, np.sin(x_values) + i0.5, lw=i0.4) plt.plot(x_values, np.cos(x_values) + i0.5, lw=i0.4)

plt.show()

`

Output :