0
0
Data Analysis Pythondata~5 mins

Line plots in Data Analysis Python

Choose your learning style9 modes available
Introduction

Line plots help us see how things change over time or in order. They connect points with lines to show trends clearly.

To track daily temperature changes over a week.
To show how sales increase or decrease each month.
To compare stock prices over several days.
To visualize how a person's weight changes over months.
To display the progress of a project over time.
Syntax
Data Analysis Python
import matplotlib.pyplot as plt

plt.plot(x_values, y_values)
plt.title('Title')
plt.xlabel('X-axis label')
plt.ylabel('Y-axis label')
plt.show()

plt.plot() draws the line connecting points.

Always call plt.show() to display the plot.

Examples
Simple line plot with four points connected by lines.
Data Analysis Python
import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
plt.plot(x, y)
plt.show()
Line plot with circle markers, dashed red line, and labels.
Data Analysis Python
import matplotlib.pyplot as plt

x = [0, 1, 2, 3]
y = [5, 15, 10, 20]
plt.plot(x, y, marker='o', linestyle='--', color='red')
plt.title('Example Line Plot')
plt.xlabel('Time')
plt.ylabel('Value')
plt.show()
Sample Program

This program shows sales numbers over 5 days using a blue line with circle markers. It also adds a grid for easier reading.

Data Analysis Python
import matplotlib.pyplot as plt

# Data: days and sales
days = [1, 2, 3, 4, 5]
sales = [100, 120, 90, 150, 130]

plt.plot(days, sales, marker='o', color='blue')
plt.title('Sales Over 5 Days')
plt.xlabel('Day')
plt.ylabel('Sales')
plt.grid(True)
plt.show()
OutputSuccess
Important Notes

Line plots work best when x-values are ordered or represent time.

You can add markers to points to make them easier to see.

Use labels and titles to explain what the plot shows.

Summary

Line plots connect data points to show trends over time or order.

Use plt.plot() to create line plots in Python.

Adding labels and markers makes plots clearer and easier to understand.