Spaces:
Running
Running
File size: 30,379 Bytes
3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc 3ca3212 13d9acc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Data Visualization Masterclass</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="app flex">
<!-- Sidebar Navigation -->
<aside class="sidebar" id="sidebar">
<h1 class="sidebar__title">π Data Visualization</h1>
<nav>
<h3 class="sidebar__section">Foundations</h3>
<ul class="nav__list" id="navList">
<li><a href="#intro" class="nav__link">π― Why Visualize Data?</a></li>
<li><a href="#perception" class="nav__link">ποΈ Visual Perception</a></li>
<li><a href="#grammar" class="nav__link">π Grammar of Graphics</a></li>
<li><a href="#choosing-charts" class="nav__link">π¨ Choosing the Right Chart</a></li>
</ul>
<h3 class="sidebar__section">Matplotlib Essentials</h3>
<ul class="nav__list">
<li><a href="#matplotlib-anatomy" class="nav__link">π¬ Figure Anatomy</a></li>
<li><a href="#basic-plots" class="nav__link">π Basic Plots</a></li>
<li><a href="#subplots" class="nav__link">π² Subplots & Layouts</a></li>
<li><a href="#styling" class="nav__link">π¨ Styling & Themes</a></li>
</ul>
<h3 class="sidebar__section">Seaborn Statistical Viz</h3>
<ul class="nav__list">
<li><a href="#seaborn-intro" class="nav__link">π Seaborn Overview</a></li>
<li><a href="#distributions" class="nav__link">π Distribution Plots</a></li>
<li><a href="#relationships" class="nav__link">π Relationship Plots</a></li>
<li><a href="#categorical" class="nav__link">π¦ Categorical Plots</a></li>
<li><a href="#heatmaps" class="nav__link">π₯ Heatmaps & Clusters</a></li>
</ul>
<h3 class="sidebar__section">Interactive Visualization</h3>
<ul class="nav__list">
<li><a href="#plotly" class="nav__link">π Plotly Express</a></li>
<li><a href="#animations" class="nav__link">π¬ Animations</a></li>
<li><a href="#dashboards" class="nav__link">π± Dashboards (Streamlit)</a></li>
</ul>
<h3 class="sidebar__section">Advanced Topics</h3>
<ul class="nav__list">
<li><a href="#geospatial" class="nav__link">πΊοΈ Geospatial Viz</a></li>
<li><a href="#3d-plots" class="nav__link">π² 3D Visualization</a></li>
<li><a href="#storytelling" class="nav__link">π Data Storytelling</a></li>
</ul>
</nav>
</aside>
<!-- Main Content -->
<main class="content" id="content">
<!-- ============================ 1. INTRO ============================ -->
<section id="intro" class="topic-section">
<h2>π― Why Visualize Data?</h2>
<p>Data visualization transforms abstract numbers into visual stories. The human brain processes images 60,000Γ
faster than text. Visualization helps us <strong>explore</strong>, <strong>analyze</strong>, and
<strong>communicate</strong> data effectively.</p>
<div class="info-card">
<strong>Anscombe's Quartet:</strong> Four datasets with nearly identical statistical properties (mean,
variance, correlation) that look completely different when plotted. This demonstrates why visualization is
essential - statistics alone can be misleading!
</div>
<div class="canvas-wrapper">
<canvas id="canvas-anscombe" width="800" height="400"></canvas>
</div>
<h3>Three Purposes of Visualization</h3>
<div class="info-card">
<strong>1. Exploratory:</strong> Discover patterns, anomalies, and insights in your data<br>
<strong>2. Explanatory:</strong> Communicate findings to stakeholders clearly<br>
<strong>3. Confirmatory:</strong> Verify hypotheses and validate models
</div>
<div class="callout callout--insight">π‘ "The greatest value of a picture is when it forces us to notice what we
never expected to see." β John Tukey</div>
<div class="callout callout--tip">β
Always start with visualization before building ML models.</div>
</section>
<!-- ====================== 2. VISUAL PERCEPTION ================== -->
<section id="perception" class="topic-section">
<h2>ποΈ Visual Perception & Pre-attentive Attributes</h2>
<p>The human visual system can detect certain visual attributes almost instantly (< 250ms) without conscious
effort. These are called <strong>pre-attentive attributes</strong>.</p>
<div class="info-card">
<strong>Pre-attentive Attributes:</strong>
<ul>
<li><strong>Position:</strong> Most accurate for quantitative data (use X/Y axes)</li>
<li><strong>Length:</strong> Bar charts leverage this effectively</li>
<li><strong>Color Hue:</strong> Best for categorical distinctions</li>
<li><strong>Color Intensity:</strong> Good for gradients/magnitude</li>
<li><strong>Size:</strong> Bubble charts, but humans underestimate area</li>
<li><strong>Shape:</strong> Useful for categories, but limit to 5-7 shapes</li>
<li><strong>Orientation:</strong> Lines, angles</li>
</ul>
</div>
<div class="form-group">
<button id="btn-position" class="btn btn--primary">Position Encoding</button>
<button id="btn-color" class="btn btn--primary">Color Encoding</button>
<button id="btn-size" class="btn btn--primary">Size Encoding</button>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-perception" width="700" height="350"></canvas>
</div>
<h3>Cleveland & McGill's Accuracy Ranking</h3>
<div class="info-card">
<strong>Most Accurate β Least Accurate:</strong><br>
1. Position on common scale (bar chart)<br>
2. Position on non-aligned scale (multiple axes)<br>
3. Length (bar)<br>
4. Angle, Slope<br>
5. Area<br>
6. Volume, Curvature<br>
7. Color saturation, Color hue
</div>
<div class="callout callout--mistake">β οΈ Pie charts use angle (low accuracy). Bar charts are almost always
better!</div>
<div class="callout callout--tip">β
Use position for most important data, color for categories.</div>
</section>
<!-- ====================== 3. GRAMMAR OF GRAPHICS ================== -->
<section id="grammar" class="topic-section">
<h2>π The Grammar of Graphics</h2>
<p>The Grammar of Graphics (Wilkinson, 1999) is a framework for describing statistical graphics. It's the
foundation of ggplot2 (R) and influences Seaborn, Altair, and Plotly.</p>
<div class="info-card">
<strong>Components of a Graphic:</strong>
<ul>
<li><strong>Data:</strong> The dataset being visualized</li>
<li><strong>Aesthetics (aes):</strong> Mapping data to visual properties (x, y, color, size)</li>
<li><strong>Geometries (geom):</strong> Visual elements (points, lines, bars, areas)</li>
<li><strong>Facets:</strong> Subplots by categorical variable</li>
<li><strong>Statistics:</strong> Transformations (binning, smoothing, aggregation)</li>
<li><strong>Coordinates:</strong> Cartesian, polar, map projections</li>
<li><strong>Themes:</strong> Non-data visual elements (fonts, backgrounds)</li>
</ul>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-grammar" width="800" height="400"></canvas>
</div>
<div class="callout callout--insight">π‘ Understanding Grammar of Graphics makes you a better visualizer in ANY
library.</div>
</section>
<!-- ====================== 4. CHOOSING CHARTS ================== -->
<section id="choosing-charts" class="topic-section">
<h2>π¨ Choosing the Right Chart</h2>
<p>The best visualization depends on your <strong>data type</strong> and <strong>question</strong>. Here's a
decision guide:</p>
<div class="info-card">
<strong>Single Variable (Univariate):</strong><br>
β’ Continuous: Histogram, KDE, Box plot, Violin plot<br>
β’ Categorical: Bar chart, Count plot<br><br>
<strong>Two Variables (Bivariate):</strong><br>
β’ Both Continuous: Scatter plot, Line chart, Hexbin, 2D histogram<br>
β’ Continuous + Categorical: Box plot, Violin, Strip, Swarm<br>
β’ Both Categorical: Heatmap, Grouped bar chart<br><br>
<strong>Multiple Variables (Multivariate):</strong><br>
β’ Pair plot (scatterplot matrix)<br>
β’ Parallel coordinates<br>
β’ Heatmap correlation matrix<br>
β’ Faceted plots (small multiples)
</div>
<div class="form-group">
<button id="btn-comparison" class="btn btn--primary">Comparison</button>
<button id="btn-composition" class="btn btn--primary">Composition</button>
<button id="btn-distribution" class="btn btn--primary">Distribution</button>
<button id="btn-relationship" class="btn btn--primary">Relationship</button>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-choosing" width="800" height="400"></canvas>
</div>
<h3>Common Chart Mistakes</h3>
<div class="callout callout--mistake">β οΈ <strong>Pie charts for many categories</strong> - Use bar chart instead
</div>
<div class="callout callout--mistake">β οΈ <strong>3D effects on 2D data</strong> - Distorts perception</div>
<div class="callout callout--mistake">β οΈ <strong>Truncated Y-axis</strong> - Exaggerates differences</div>
<div class="callout callout--mistake">β οΈ <strong>Rainbow color scales</strong> - Not perceptually uniform</div>
</section>
<!-- ====================== 5. MATPLOTLIB ANATOMY ================== -->
<section id="matplotlib-anatomy" class="topic-section">
<h2>π¬ Matplotlib Figure Anatomy</h2>
<p>Understanding Matplotlib's object hierarchy is key to creating professional visualizations.</p>
<div class="info-card">
<strong>Hierarchical Structure:</strong><br>
<code>Figure β Axes β Axis β Tick β Label</code><br><br>
β’ <strong>Figure:</strong> The overall window/canvas<br>
β’ <strong>Axes:</strong> The actual plot area (NOT the X/Y axis!)<br>
β’ <strong>Axis:</strong> The X or Y axis with ticks and labels<br>
β’ <strong>Artist:</strong> Everything visible (lines, text, patches)
</div>
<div class="canvas-wrapper">
<canvas id="canvas-anatomy" width="800" height="500"></canvas>
</div>
<h3>Two Interfaces</h3>
<div class="info-card">
<strong>1. pyplot (MATLAB-style):</strong> Quick, implicit state<br>
<code>plt.plot(x, y)</code><br>
<code>plt.xlabel('Time')</code><br>
<code>plt.show()</code><br><br>
<strong>2. Object-Oriented (OO):</strong> Explicit, recommended for complex plots<br>
<code>fig, ax = plt.subplots()</code><br>
<code>ax.plot(x, y)</code><br>
<code>ax.set_xlabel('Time')</code>
</div>
<div class="callout callout--tip">β
Always use OO interface for publication-quality plots.</div>
</section>
<!-- ====================== 6. BASIC PLOTS ================== -->
<section id="basic-plots" class="topic-section">
<h2>π Basic Matplotlib Plots</h2>
<p>Master the fundamental plot types that form the foundation of data visualization.</p>
<div class="form-group">
<button id="btn-line" class="btn btn--primary">Line Plot</button>
<button id="btn-scatter" class="btn btn--primary">Scatter Plot</button>
<button id="btn-bar" class="btn btn--primary">Bar Chart</button>
<button id="btn-hist" class="btn btn--primary">Histogram</button>
<button id="btn-pie" class="btn btn--primary">Pie Chart</button>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-basic" width="800" height="400"></canvas>
</div>
<h3>Code Examples</h3>
<div class="info-card">
<strong>Line Plot:</strong><br>
<code>ax.plot(x, y, color='blue', linestyle='--', marker='o', label='Series A')</code><br><br>
<strong>Scatter Plot:</strong><br>
<code>ax.scatter(x, y, c=colors, s=sizes, alpha=0.7, cmap='viridis')</code><br><br>
<strong>Bar Chart:</strong><br>
<code>ax.bar(categories, values, color='steelblue', edgecolor='black')</code><br><br>
<strong>Histogram:</strong><br>
<code>ax.hist(data, bins=30, edgecolor='white', density=True)</code>
</div>
</section>
<!-- ====================== 7. SUBPLOTS ================== -->
<section id="subplots" class="topic-section">
<h2>π² Subplots & Multi-panel Layouts</h2>
<p>Combine multiple visualizations into a single figure for comprehensive analysis.</p>
<div class="form-group">
<button id="btn-grid-2x2" class="btn btn--primary">2Γ2 Grid</button>
<button id="btn-grid-uneven" class="btn btn--primary">Uneven Grid</button>
<button id="btn-gridspec" class="btn btn--primary">GridSpec</button>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-subplots" width="800" height="500"></canvas>
</div>
<div class="info-card">
<strong>Methods:</strong><br>
<code>fig, axes = plt.subplots(2, 2, figsize=(12, 10))</code><br>
<code>fig, axes = plt.subplots(2, 2, sharex=True, sharey=True)</code><br>
<code>gs = fig.add_gridspec(3, 3); ax = fig.add_subplot(gs[0, :])</code>
</div>
<div class="callout callout--tip">β
Use plt.tight_layout() or fig.set_constrained_layout(True) to prevent
overlaps.</div>
</section>
<!-- ====================== 8. STYLING ================== -->
<section id="styling" class="topic-section">
<h2>π¨ Styling & Professional Themes</h2>
<p>Transform basic plots into publication-quality visualizations.</p>
<div class="form-group">
<button id="btn-style-default" class="btn btn--primary">Default</button>
<button id="btn-style-seaborn" class="btn btn--primary">Seaborn</button>
<button id="btn-style-ggplot" class="btn btn--primary">ggplot</button>
<button id="btn-style-dark" class="btn btn--primary">Dark Background</button>
<button id="btn-style-538" class="btn btn--primary">FiveThirtyEight</button>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-styling" width="800" height="400"></canvas>
</div>
<div class="info-card">
<strong>Available Styles:</strong><br>
<code>plt.style.available</code> β Lists all built-in styles<br>
<code>plt.style.use('seaborn-v0_8-whitegrid')</code><br>
<code>with plt.style.context('dark_background'):</code>
</div>
<h3>Color Palettes</h3>
<div class="info-card">
<strong>Perceptually Uniform:</strong> viridis, plasma, inferno, magma, cividis<br>
<strong>Sequential:</strong> Blues, Greens, Oranges (for magnitude)<br>
<strong>Diverging:</strong> coolwarm, RdBu (for +/- deviations)<br>
<strong>Categorical:</strong> tab10, Set2, Paired (discrete groups)
</div>
</section>
<!-- ====================== 9. SEABORN INTRO ================== -->
<section id="seaborn-intro" class="topic-section">
<h2>π Seaborn: Statistical Visualization</h2>
<p>Seaborn is a high-level library built on Matplotlib that makes statistical graphics beautiful and easy.</p>
<div class="info-card">
<strong>Why Seaborn?</strong>
<ul>
<li>Beautiful default styles and color palettes</li>
<li>Works seamlessly with Pandas DataFrames</li>
<li>Statistical estimation built-in (confidence intervals, regression)</li>
<li>Faceting for multi-panel figures</li>
<li>Functions organized by plot purpose</li>
</ul>
</div>
<h3>Seaborn Function Categories</h3>
<div class="info-card">
<strong>Figure-level:</strong> Create entire figures (displot, relplot, catplot)<br>
<strong>Axes-level:</strong> Draw on specific axes (histplot, scatterplot, boxplot)<br><br>
<strong>By Purpose:</strong><br>
β’ <strong>Distribution:</strong> histplot, kdeplot, ecdfplot, rugplot<br>
β’ <strong>Relationship:</strong> scatterplot, lineplot, regplot<br>
β’ <strong>Categorical:</strong> stripplot, swarmplot, boxplot, violinplot, barplot<br>
β’ <strong>Matrix:</strong> heatmap, clustermap
</div>
<div class="canvas-wrapper">
<canvas id="canvas-seaborn-intro" width="800" height="400"></canvas>
</div>
</section>
<!-- ====================== 10. DISTRIBUTIONS ================== -->
<section id="distributions" class="topic-section">
<h2>π Distribution Plots</h2>
<p>Visualize the distribution of a single variable or compare distributions across groups.</p>
<div class="form-group">
<button id="btn-histplot" class="btn btn--primary">Histogram</button>
<button id="btn-kdeplot" class="btn btn--primary">KDE Plot</button>
<button id="btn-ecdfplot" class="btn btn--primary">ECDF</button>
<button id="btn-rugplot" class="btn btn--primary">Rug Plot</button>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-distributions" width="800" height="400"></canvas>
</div>
<div class="info-card">
<strong>Histogram vs KDE:</strong><br>
β’ Histogram: Discrete bins, shows raw counts<br>
β’ KDE: Smooth curve, estimates probability density<br>
β’ Use both together: <code>sns.histplot(data, kde=True)</code>
</div>
<div class="callout callout--insight">π‘ ECDF (Empirical Cumulative Distribution Function) avoids binning issues
entirely.</div>
</section>
<!-- ====================== 11. RELATIONSHIPS ================== -->
<section id="relationships" class="topic-section">
<h2>π Relationship Plots</h2>
<p>Explore relationships between two or more continuous variables.</p>
<div class="form-group">
<button id="btn-scatter-hue" class="btn btn--primary">Scatter + Hue</button>
<button id="btn-regplot" class="btn btn--primary">Regression Plot</button>
<button id="btn-residplot" class="btn btn--primary">Residual Plot</button>
<button id="btn-pairplot" class="btn btn--primary">Pair Plot</button>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-relationships" width="800" height="500"></canvas>
</div>
<div class="info-card">
<strong>Key Functions:</strong><br>
<code>sns.scatterplot(data=df, x='x', y='y', hue='category', size='magnitude')</code><br>
<code>sns.regplot(data=df, x='x', y='y', scatter_kws={'alpha':0.5})</code><br>
<code>sns.pairplot(df, hue='species', diag_kind='kde')</code>
</div>
</section>
<!-- ====================== 12. CATEGORICAL ================== -->
<section id="categorical" class="topic-section">
<h2>π¦ Categorical Plots</h2>
<p>Visualize distributions and comparisons across categorical groups.</p>
<div class="form-group">
<button id="btn-stripplot" class="btn btn--primary">Strip Plot</button>
<button id="btn-swarmplot" class="btn btn--primary">Swarm Plot</button>
<button id="btn-boxplot" class="btn btn--primary">Box Plot</button>
<button id="btn-violinplot" class="btn btn--primary">Violin Plot</button>
<button id="btn-barplot" class="btn btn--primary">Bar Plot</button>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-categorical" width="800" height="400"></canvas>
</div>
<div class="info-card">
<strong>When to Use:</strong><br>
β’ <strong>Strip/Swarm:</strong> Show all data points (small datasets)<br>
β’ <strong>Box:</strong> Summary statistics (median, quartiles, outliers)<br>
β’ <strong>Violin:</strong> Full distribution shape + summary<br>
β’ <strong>Bar:</strong> Mean/count with error bars
</div>
</section>
<!-- ====================== 13. HEATMAPS ================== -->
<section id="heatmaps" class="topic-section">
<h2>π₯ Heatmaps & Correlation Matrices</h2>
<p>Visualize matrices of values using color intensity. Essential for EDA correlation analysis.</p>
<div class="form-group">
<button id="btn-heatmap-basic" class="btn btn--primary">Basic Heatmap</button>
<button id="btn-corr-matrix" class="btn btn--primary">Correlation Matrix</button>
<button id="btn-clustermap" class="btn btn--primary">Clustermap</button>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-heatmaps" width="800" height="500"></canvas>
</div>
<div class="info-card">
<strong>Best Practices:</strong><br>
β’ Always annotate with values: <code>annot=True</code><br>
β’ Use diverging colormap for correlation: <code>cmap='coolwarm', center=0</code><br>
β’ Mask upper/lower triangle: <code>mask=np.triu(np.ones_like(corr))</code><br>
β’ Square cells: <code>square=True</code>
</div>
<div class="callout callout--insight">π‘ Clustermap automatically clusters similar rows/columns together.</div>
</section>
<!-- ====================== 14. PLOTLY ================== -->
<section id="plotly" class="topic-section">
<h2>π Plotly Express: Interactive Visualization</h2>
<p>Plotly creates interactive, web-based visualizations with zoom, pan, hover tooltips, and more.</p>
<div class="info-card">
<strong>Why Plotly?</strong>
<ul>
<li>Interactive out of the box (zoom, pan, select)</li>
<li>Hover tooltips with data details</li>
<li>Export as HTML, PNG, or embed in dashboards</li>
<li>Works in Jupyter, Streamlit, Dash</li>
<li>plotly.express is the high-level API (like Seaborn for Matplotlib)</li>
</ul>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-plotly" width="800" height="400"></canvas>
</div>
<div class="info-card">
<strong>Common Functions:</strong><br>
<code>px.scatter(df, x='x', y='y', color='category', size='value', hover_data=['name'])</code><br>
<code>px.line(df, x='date', y='price', color='stock')</code><br>
<code>px.bar(df, x='category', y='count', color='group', barmode='group')</code><br>
<code>px.histogram(df, x='value', nbins=50, marginal='box')</code>
</div>
</section>
<!-- ====================== 15. ANIMATIONS ================== -->
<section id="animations" class="topic-section">
<h2>π¬ Animated Visualizations</h2>
<p>Add time dimension to your visualizations with animations.</p>
<div class="form-group">
<button id="btn-animate" class="btn btn--primary">βΆ Play Animation</button>
<button id="btn-stop" class="btn btn--primary">βΉ Stop</button>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-animation" width="800" height="400"></canvas>
</div>
<div class="info-card">
<strong>Plotly Animation:</strong><br>
<code>px.scatter(df, x='gdp', y='life_exp', animation_frame='year', animation_group='country', size='pop', color='continent')</code><br><br>
<strong>Matplotlib Animation:</strong><br>
<code>from matplotlib.animation import FuncAnimation</code><br>
<code>ani = FuncAnimation(fig, update_func, frames=100, interval=50)</code>
</div>
<div class="callout callout--tip">β
Hans Rosling's Gapminder is the classic example of animated scatter plots!
</div>
</section>
<!-- ====================== 16. DASHBOARDS ================== -->
<section id="dashboards" class="topic-section">
<h2>π± Interactive Dashboards with Streamlit</h2>
<p>Build interactive web apps for data exploration without web development experience.</p>
<div class="info-card">
<strong>Streamlit Basics:</strong><br>
<code>streamlit run app.py</code><br><br>
<code>import streamlit as st</code><br>
<code>st.title("My Dashboard")</code><br>
<code>st.slider("Select value", 0, 100, 50)</code><br>
<code>st.selectbox("Choose", ["A", "B", "C"])</code><br>
<code>st.plotly_chart(fig)</code>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-dashboard" width="800" height="400"></canvas>
</div>
<div class="callout callout--insight">π‘ Streamlit auto-reruns when input changes - no callbacks needed!</div>
</section>
<!-- ====================== 17. GEOSPATIAL ================== -->
<section id="geospatial" class="topic-section">
<h2>πΊοΈ Geospatial Visualization</h2>
<p>Visualize geographic data with maps, choropleth, and point plots.</p>
<div class="form-group">
<button id="btn-choropleth" class="btn btn--primary">Choropleth Map</button>
<button id="btn-scatter-geo" class="btn btn--primary">Scatter on Map</button>
<button id="btn-heatmap-geo" class="btn btn--primary">Density Map</button>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-geo" width="800" height="500"></canvas>
</div>
<div class="info-card">
<strong>Libraries:</strong><br>
β’ <strong>Plotly:</strong> <code>px.choropleth(df, locations='country', color='value')</code><br>
β’ <strong>Folium:</strong> Interactive Leaflet maps<br>
β’ <strong>Geopandas + Matplotlib:</strong> Static maps with shapefiles<br>
β’ <strong>Kepler.gl:</strong> Large-scale geospatial visualization
</div>
</section>
<!-- ====================== 18. 3D PLOTS ================== -->
<section id="3d-plots" class="topic-section">
<h2>π² 3D Visualization</h2>
<p>Visualize three-dimensional relationships with surface plots, scatter plots, and more.</p>
<div class="form-group">
<button id="btn-3d-scatter" class="btn btn--primary">3D Scatter</button>
<button id="btn-3d-surface" class="btn btn--primary">Surface Plot</button>
<button id="btn-3d-wireframe" class="btn btn--primary">Wireframe</button>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-3d" width="800" height="500"></canvas>
</div>
<div class="callout callout--mistake">β οΈ 3D plots can obscure data. Often, multiple 2D views are more effective.
</div>
<div class="callout callout--tip">β
Use Plotly for interactive 3D (rotate, zoom) instead of static Matplotlib
3D.</div>
</section>
<!-- ====================== 19. STORYTELLING ================== -->
<section id="storytelling" class="topic-section">
<h2>π Data Storytelling</h2>
<p>Transform visualizations into compelling narratives that drive action.</p>
<div class="info-card">
<strong>The Data Storytelling Framework:</strong>
<ol>
<li><strong>Context:</strong> Why does this matter? Who is the audience?</li>
<li><strong>Data:</strong> What insights did you discover?</li>
<li><strong>Narrative:</strong> What's the storyline (beginning, middle, end)?</li>
<li><strong>Visual:</strong> Which chart best supports the story?</li>
<li><strong>Call to Action:</strong> What should the audience do?</li>
</ol>
</div>
<div class="canvas-wrapper">
<canvas id="canvas-storytelling" width="800" height="400"></canvas>
</div>
<h3>Design Principles</h3>
<div class="info-card">
<strong>Remove Clutter:</strong> Eliminate chartjunk, gridlines, borders<br>
<strong>Focus Attention:</strong> Use color strategically (grey + accent)<br>
<strong>Think Like a Designer:</strong> Alignment, white space, hierarchy<br>
<strong>Tell a Story:</strong> Title = conclusion, not description<br>
<strong>Bad:</strong> "Sales by Region"<br>
<strong>Good:</strong> "West Region Sales Dropped 23% in Q4"
</div>
<div class="callout callout--insight">π‘ "If you can't explain it simply, you don't understand it well enough."
β Einstein</div>
<div class="callout callout--tip">β
Read "Storytelling with Data" by Cole Nussbaumer Knaflic</div>
</section>
<!-- Footer -->
<footer
style="text-align: center; padding: 40px 20px; border-top: 1px solid var(--border-color); margin-top: 60px;">
<p style="color: var(--text-secondary);">π Data Visualization Masterclass | Part of the Data Science & AI
Curriculum</p>
<a href="../index.html" class="btn btn--primary" style="margin-top: 16px;">β Back to Home</a>
</footer>
</main>
</div>
<script src="app.js"></script>
</body>
</html> |