Course contentsShow
← Data Science
Lesson 1264 of 2,14532. Visualization with Matplotlib and SeabornFree lesson

Line Plots: Continuous Data and Trends

Learn to create and customize line plots for time series and continuous relationships using plot() and styling options.

Line Plots: Continuous Data and Trends

You'll learn how to create and customize line plots to visualize continuous data and trends over time or ordered variables.

Why Line Plots?

Line plots excel at showing how values change continuously across an ordered dimension—most commonly time, but also temperature, distance, or any sequential variable. Think of them as connecting the dots to reveal the story of change. Unlike scatter plots that show individual relationships, line plots emphasize the flow and trajectory of data.

Creating Basic Line Plots

You've already seen plot() in action. For continuous data, it automatically draws connected lines between points:

import matplotlib.pyplot as plt
import numpy as np

# Time series data
months = np.arange(1, 13)
sales = [150, 180, 220, 200, 250, 300, 320, 310, 290, 330, 380, 400]

plt.plot(months, sales)
plt.xlabel('Month')
plt.ylabel('Sales ($1000s)')
plt.title('Monthly Sales Trend')
plt.show()

Emphasizing Trends with Styling

Customize your line plots to highlight patterns:

plt.plot(months, sales, color='steelblue', linewidth=2.5, 
         linestyle='-', marker='o', markersize=6)

The continuous line emphasizes the trend, while markers show actual data points—useful for sparse datasets where you want to see both pattern and precision.

Multiple Trends

Compare trends by plotting multiple lines with clear differentiation:

revenue = [160, 190, 230, 210, 260, 310, 330, 320, 300, 340, 390, 410]
plt.plot(months, sales, label='Sales', linewidth=2)
plt.plot(months, revenue, label='Revenue', linewidth=2, linestyle='--')
plt.legend()

Key Takeaway: Line plots reveal continuous trends and changes over ordered data by connecting points into flowing trajectories—use plot() with styling options to emphasize patterns and compare multiple series effectively.