Change the line width in Matplotlib

Python

Matplotlib

Line

Change width

Luc B.

Python

Matplotlib

Line Plot

Changing the line width in a Matplotlib plot is a simple way to create emphasis, reduce clutter, and generally improve the asthetics of plots.

Code Example

Use the linewidth (or just lw) parameter to plt.plot() to change the line width in Matplotlib.

import matplotlib.pyplot as plt
import numpy as np

x_values = np.arange(0, 7)
y_values = np.array([0.27, 0.32, 0.35, 0.49, 0.55, 0.7, 0.95])

# Adjust the line widths here
plt.plot(x_values, y_values, linewidth=1)
plt.plot(x_values, y_values + 0.5, lw=5)

plt.legend(['Skinny Line', 'Thick Line'])
plt.show()

png