Line Plot

Python · Data Visualization

Theory

A line plot joins data points in order, so the slope of the line shows how a value changes from one step to the next. It is the standard chart for time series: monthly sales, daily temperature, website visits. ax.plot(x, y) draws one line; calling it again on the same Axes adds another, and label='Online' plus ax.legend() tells them apart.

Styling arguments control the look: marker='o' shows each point, linestyle='--' makes a dashed line, linewidth sets thickness and color picks the colour. The x values should be ordered, otherwise the line zig-zags back and forth. With five months of online sales [120, 135, 160, 150, 190], the line rises, dips in April and jumps in May, and the size of each step is the month-on-month change.

Why we use it

Trends, seasonality and sudden changes are easiest to see as a line. Comparing several lines on one Axes shows which series grows faster or when they cross, something hard to read from a table.

When to use it

Use a line plot when the x-axis is ordered, especially time. For unordered categories (cities, products) use a bar chart, and for the relationship between two measured variables use a scatter plot. Keep to a handful of lines so the chart stays readable.

How it works

  1. Ordered x values and one or more y series
  2. Is x ordered (time, sequence)? Yes: Line plot fits. No: Use bar (categories) or scatter (two measures).
  3. ax.plot(x, y, label=...) for each series
  4. Add markers, axis labels and ax.legend()
  5. Trend chart: read slopes and crossings

Syntax

ax.plot(x, y, label='name', marker='o', linestyle='-', linewidth=2, color='tab:blue')
ax.legend()

Example

months = ['Jan', 'Feb', 'Mar']
fig, ax = plt.subplots()
ax.plot(months, [120, 135, 160], marker='o', label='Online')
ax.legend()

Key points

Python topics

Getting Started

Variables & Data Types

Operators

Strings

Lists

Tuples

Sets

Dictionaries

Control Flow

Loops

Functions & OOP

Working with Data

Tooling & Errors

File Handling

Exception Handling

NumPy Library

Pandas Basics

Data Cleaning

Combining DataFrames (SQL Joins & Unions)

GroupBy & SQL-Style Analytics

Reshaping & Workflow

Data Visualization

Machine Learning (Scikit-Learn)

Advanced Python & AI

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Python for Data Analysts

From basics to business insights — the complete step-by-step Python roadmap. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Python Online 141 Python questions for data analysts — strings, records, dates, statistics and regex — with hidden tests and instant verdicts. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Python  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs real Python 3.12 in your browser (first run loads the engine)
{{ liveOutput }}
{{ liveError }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic