Saturday, 28 February 2026

๐Ÿญ Day 42: Lollipop Chart in Python

 

๐Ÿญ Day 42: Lollipop Chart in Python


๐Ÿ”น What is a Lollipop Chart?

A Lollipop Chart is similar to a bar chart, but:

  • Instead of thick bars → it uses a thin line

  • A dot is placed at the end of the line

It looks cleaner and less heavy than a bar chart.


๐Ÿ”น When Should You Use It?

Use a lollipop chart when:

  • Comparing categories

  • Showing rankings

  • Creating minimal dashboards

  • Replacing traditional bar charts


๐Ÿ“Š What We’re Visualizing

Organic Web Traffic Sources:

  • Pinterest → 12

  • Instagram → 18

  • Blog → 29

  • SEO → 34

  • Referrals → 45

This helps us quickly see which channel drives the most traffic.


๐Ÿง‘‍๐Ÿ’ป Python Implementation (Plotly)


✅ Step 1: Import Library

import plotly.graph_objects as go

We’re using Plotly Graph Objects for full customization.


✅ Step 2: Define Categories & Values

categories = ['Pinterest', 'Instagram', 'Blog', 'SEO', 'Referrals'] 
values = [12, 18, 29, 34, 45]

✅ Step 3: Create Figure

fig = go.Figure()

✅ Step 4: Add the Stem Lines

for i, (cat, val) in enumerate(zip(categories, values)):
fig.add_trace(go.Scatter(
x=[cat, cat], y=[0, val], mode='lis',
line=dict(color='#DBC1AD', width=2), hoverinfo='none'
))

Each category gets a vertical line from 0 to its value.


✅ Step 5: Add the Circular Markers

fig.add_trace(go.Scatter( x=categories, y=values, mode='markers+text', text=values, textposition="middle center", marker=dict( size=60, color='#E5989B', line=dict(width=5, color='white')
),
textfont=dict(family="serif", size=14, color="white")
))

This creates the “lollipop head”:

  • Large pastel circles

  • White border

  • Values displayed inside

  • Serif typography for elegance


✅ Step 6: Layout Styling

fig.update_layout( title=dict(text="Organic Web Traffic", x=0.5, font=dict(family="serif", size=26, color="#4A4A4A")), paper_bgcolor='#FAF9F6', plot_bgcolor='#FAF9F6', showlegend=False, width=800, height=700, xaxis=dict(showgrid=False, linecolor='#DBC1AD', tickfont=dict(family="serif", size=14)), yaxis=dict(showgrid=False, visible=False)
)

✨ Styling Highlights:

  • Soft linen background (#FAF9F6)

  • Minimal gridlines

  • Hidden Y-axis

  • Elegant serif typography

  • Balanced spacing


๐Ÿ“ˆ What the Chart Reveals

  • Referrals generate the highest traffic (45)

  • SEO is second strongest (34)

  • Pinterest contributes the least (12)

  • Clear upward trend across channels

Because the chart removes heavy bars, your focus stays on:

✔ Ranking
✔ Comparison
✔ Clean design


๐Ÿ’ก Why Use a Lollipop Chart?

✔ Cleaner than bar charts
✔ Visually modern
✔ Less ink, more clarity
✔ Perfect for aesthetic dashboards
✔ Great for presentations & portfolios


0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (212) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (28) Azure (9) BI (10) Books (262) Bootcamp (1) C (78) C# (12) C++ (83) Course (86) Coursera (300) Cybersecurity (29) data (2) Data Analysis (26) Data Analytics (20) data management (15) Data Science (309) Data Strucures (16) Deep Learning (127) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (18) Finance (10) flask (3) flutter (1) FPL (17) Generative AI (65) Git (10) Google (50) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (41) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (254) Meta (24) MICHIGAN (5) microsoft (10) Nvidia (8) Pandas (13) PHP (20) Projects (32) Python (1260) Python Coding Challenge (1054) Python Mistakes (50) Python Quiz (432) Python Tips (5) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (46) Udemy (17) UX Research (1) web application (11) Web development (8) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)