Styling and Colours

Python · Data Visualization

Theory

Colour should carry meaning, not decoration. For categories (cities, products) use a qualitative palette of clearly different hues, such as matplotlib's default 'tab10'. For ordered values (low to high sales) use a sequential colormap like 'viridis' or 'Blues', where lightness changes steadily. For values around a midpoint (profit vs loss, correlation from -1 to 1) use a diverging map such as 'RdBu', with the midpoint in the centre.

A strong technique is highlighting: draw everything in grey and give only the bar that matters a colour. Colours can be names ('tab:blue'), hex codes ('#1f77b4') or a list, one per bar. plt.style.use('ggplot') or a temporary with plt.style.context('ggplot'): block changes the overall look, and plt.rcParams['font.size'] = 12 sets defaults. Avoid red-green pairs, which many colour-blind readers cannot tell apart.

Why we use it

Good colour choices make the important point jump out and keep charts readable for everyone, including colour-blind readers. Poor choices, such as rainbow maps for ordered data, can mislead or hide the message.

When to use it

Use a qualitative palette for categories, sequential for magnitudes, diverging for values around zero, and grey plus one accent to highlight. Set a style once at the top of a notebook so all charts match.

How it works

  1. What does colour need to show?
  2. Different categories? Yes: Qualitative palette (tab10). No: Continue.
  3. Values with a meaningful midpoint (e.g. 0)? Yes: Diverging map (RdBu). No: Sequential map (viridis, Blues).
  4. Highlight the key item; mute the rest in grey
  5. Check it still reads in greyscale or for colour-blind readers
  6. Colour that carries meaning

Syntax

ax.bar(x, y, color=['lightgray', 'tab:orange', ...])
ax.scatter(x, y, c=values, cmap='viridis')
plt.style.use('ggplot')
with plt.style.context('ggplot'): ...
plt.rcParams['font.size'] = 12

Example

colors = ['lightgray', 'lightgray', 'tab:orange']
ax.bar(['Jaipur', 'Pune', 'Delhi'], [120, 90, 200], color=colors)

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