MatplotlibXBy @CodeWithMunnaX
Catalog
Track: Beginner
Styling10 mins

06. Colors, Hex Codes & Named Palettes

Color is the most emotionally resonant and visually immediate aspect of any chart. Matplotlib supports named colors, 6-digit hex strings (`#6366F1`), and 4-float RGBA tuples.

Mental Model Intuition

Mixing paints on a palette: you can ask for 'crimson' by name, enter its exact digital recipe `#E11D48`, or dilute it with water (alpha).

Core Concepts & Mechanics

Color Input FormatsFormats

Named colors ('red', 'teal'), Hex strings ('#6366F1'), RGB tuples `(0.2, 0.4, 0.8)`, and RGBA tuples `(0.2, 0.4, 0.8, 0.5)`.

Hex codes are the industry standard for brand-consistent charts in reports and web apps.
plt.plot(x, y, color='#00D9C0')

Common Beginner Mistakes & Pro Fixes

Avoid the top errors and bad plotting practices that trip up new Python developers

Troubleshooting

Quick Lesson Takeaways

  • Hex strings (`#RRGGBB`) provide accurate color control.
  • Named colors include CSS strings ('navy', 'crimson', 'teal').
  • RGB tuples require values normalized to 0.0 - 1.0.
Topic 6 • Python IDE
Python 3.12 • Matplotlib
Run Python code to inspect terminal output.

Real-World Datasets (1-Click Switcher)

Switch from abstract numbers to relatable Cricket, Cinema & Business charts

5 Curated Datasets

Hands-on Challenge: Apply Hex Color

+50 XP

Write Matplotlib code to solve the objective and see your live plot render

Objective Instructions:

Plot `x=[1, 2, 3]` and `y=[5, 2, 8]` with hex color `#38EF7D` and `linewidth=3`.

Required Keywords:✓ #38EF7D✓ color
Challenge Code Editor
Challenge Output GraphLive Vector Preview
Write code on the left to render live challenge plot
End of Lesson Knowledge Check

Quick Mini Quiz: 2 Concept Questions

Test your understanding to unlock the lesson completion badge

Q1

Which Matplotlib function is used to create a standard continuous 2D line plot?

Q2

What must you call after specifying label='...' so that the legend actually appears on the canvas?

0 of 2 answered