Showing posts with label Visualization Techniques. Show all posts
Showing posts with label Visualization Techniques. Show all posts

Wednesday, January 8, 2025

Animating a Growing Circle with Python and Matplotlib


Circle Radius Animation in Python – Step-by-Step Guide

๐ŸŽฅ Growing Circle Animation – Learn Step by Step

Imagine a small dot at the center of your screen… slowly expanding into a larger circle. This simple animation teaches an important concept: how to visually represent change over time using math and programming.


๐Ÿ“š Table of Contents


๐Ÿ’ก Concept Overview

The goal is simple:

  • Start with a tiny circle
  • Gradually increase its radius
  • Keep it centered at (0, 0)
  • Create a smooth animation
This is a perfect example of combining math + visualization.

๐Ÿ“ Mathematics Behind the Animation

1. Circle Equation

\[ x^2 + y^2 = r^2 \]

This defines a circle centered at the origin.

2. Radius Growth Function

\[ r = i \times 0.5 \]

Where:

  • r = radius
  • i = frame number
๐Ÿ‘‰ Each frame increases the radius linearly.

3. Time-Based Animation

\[ Time = frames \times interval \]

Example:

\[ 30 \times 50ms = 1500ms (1.5 seconds) \]


⚙️ Step-by-Step Breakdown

Click to expand steps
  • Create 2D plot with limits (-10 to 10)
  • Initialize small circle
  • Update radius each frame
  • Redraw circle smoothly
  • Maintain equal aspect ratio

๐Ÿ’ป Python Code

import matplotlib.pyplot as plt import matplotlib.animation as animation fig, ax = plt.subplots() ax.set_xlim(-10, 10) ax.set_ylim(-10, 10) ax.set_aspect('equal') circle = plt.Circle((0, 0), 0.05) ax.add_patch(circle) def update(frame): radius = frame * 0.5 circle.set_radius(radius) return circle, ani = animation.FuncAnimation(fig, update, frames=30, interval=50) plt.title("Simple Circle Animation") plt.show()

๐Ÿ–ฅ️ Output Description

What you will see
- A small circle appears at the center
- It expands smoothly outward
- Growth is continuous and fluid
- Ends as a large circle within bounds

๐Ÿ’ก Key Takeaways

  • Animations are just repeated updates over time
  • Math controls motion and growth
  • Linear functions create smooth scaling
  • Visualization improves understanding

๐ŸŽฏ Final Thought

What starts as a simple expanding circle is actually a powerful lesson in how math and code work together to create motion.

Once you understand this, you can animate anything.

Saturday, December 21, 2024

Visualizing Data: A Pie Chart Representation of Movies vs TV Shows


Pie Chart Visualization – Movies vs TV Shows (Matplotlib Guide)

๐Ÿ“Š Visualizing Movies vs TV Shows Using Pie Charts

Data visualization is one of the most powerful ways to understand information quickly. In this guide, we’ll explore how to create a pie chart to compare Movies and TV Shows using Python.


๐Ÿ“š Table of Contents


๐Ÿฅง What is a Pie Chart?

A pie chart shows how a whole is divided into parts. Each slice represents a percentage of the total.

๐Ÿ‘‰ Think of it like a pizza where each slice represents a category.

๐Ÿ“ Math Behind the Pie Chart

To calculate percentages, we use:

\[ Percentage = \frac{Value}{Total} \times 100 \]

Example Calculation:

Total:

\[ 4265 + 1969 = 6234 \]

Movies:

\[ \frac{4265}{6234} \times 100 \approx 68.32\% \]

TV Shows:

\[ \frac{1969}{6234} \times 100 \approx 31.68\% \]

๐Ÿ‘‰ This is exactly what the pie chart will display visually.

๐Ÿ’ป Code Example

import matplotlib.pyplot as plt plt.pie( [4265, 1969], labels=['Movies', 'TV Shows'], textprops={'color': "black"}, autopct='%.2f', explode=(0, 0.1) ) plt.title('Movies VS TV in %', color="Black") plt.show()

๐Ÿ–ฅ️ CLI Output

Click to View Output
Pie Chart Rendered Successfully

Movies: 68.32%
TV Shows: 31.68%
TV Shows slice highlighted 

๐Ÿ” Code Breakdown

Step-by-step Explanation
  • plt.pie() → Creates the chart
  • labels → Names of categories
  • autopct → Displays percentage
  • explode → Highlights TV Shows slice
  • title → Adds context

๐Ÿ‘️ How to Read the Chart

  • The larger slice = Movies
  • The smaller, separated slice = TV Shows
  • Percentages show exact contribution
๐Ÿ‘‰ Exploding a slice helps draw attention to important data.

๐Ÿ’ก Key Takeaways

  • Pie charts show proportions clearly
  • Math ensures accurate percentages
  • Explode feature improves visualization
  • Matplotlib makes it easy to implement

๐ŸŽฏ Final Thought

A simple pie chart can turn raw numbers into meaningful insights. With just a few lines of Python, you can communicate data clearly and effectively.

Featured Post

How HMT Watches Lost the Time: A Deep Dive into Disruptive Innovation Blindness in Indian Manufacturing

The Rise and Fall of HMT Watches: A Story of Brand Dominance and Disruptive Innovation Blindness The Rise and Fal...

Popular Posts