Line chart in Matplotlib - Python

Last Updated : 14 Jan, 2026

A line chart or line plot is a graphical representation used to show the relationship between two continuous variables by connecting data points with a straight line. It is commonly used to visualize trends, patterns or changes over time.

In Matplotlib line charts are created using the pyplot sublibrary which provides simple and flexible functions for plotting data. In a line chart, the x-axis typically represents the independent variable while the y-axis represents the dependent variable.

Syntax: plt.plot(x, y, color, linestyle, linewidth, marker)

where:

  • \bm{x}: The values for the x-axis
  • \bm{y}: The corresponding values for the y-axis
  • color: Specifies the color of the line
  • linestyle: Defines the style of the line
  • linewidth: Controls the thickness of the line
  • marker: Adds markers at data points

Consider a simple example where we visualise the weekly temperature using a line chart in Matplotlib

Python
import matplotlib.pyplot as plt
import numpy as np

days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
temperature = [22, 24, 23, 26, 25]

plt.plot(days, temperature, marker='o')
plt.title('Weekly Temperature')
plt.xlabel('Days')
plt.ylabel('Temperature (°C)')
plt.show()

Output: