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

import matplotlib.pyplot as plt

import numpy as np

x_values = np.arange( 0 , 10 )

y_values = np.arange( 0 , 10 )

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

plt.plot(x_values, y_values)

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

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

plt.show()

Output :

Example 2 :

Python3

import matplotlib.pyplot as plt

import numpy as np

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

y_values = np.sin(x_values)

for i in range ( 20 ):

`` plt.plot(x_values, y_values + i * 0.5 , lw = i * 0.5 )

plt.show()

Output :

Example 3 :

Python3

import matplotlib.pyplot as plt

import numpy as np

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

for i in range ( 20 ):

`` plt.plot(x_values, np.sin(x_values) + i * 0.5 , lw = i * 0.4 )

`` plt.plot(x_values, np.cos(x_values) + i * 0.5 , lw = i * 0.4 )

plt.show()

Output :

Similar Reads