Python Matplotlib: Plot Performance Grid of Multiple Stocks with Dynamic Subplots | Part 7 ๐Ÿ–ผ๏ธ

Matt Macarty ยท Beginner ยท๐Ÿ“Š Data Analytics & Business Intelligence ยท4y ago
Skills: BI Tools53%

About this lesson

@MattMacarty ## ๐Ÿ Python Matplotlib: Plot Performance Grid of Multiple Stocks with Dynamic Subplots | Part 7 Welcome to Part 7 of the **Python Stock Analysis Course**! This video focuses on **advanced data visualization** using **Matplotlib**. We solve the challenge of plotting the relative performance of numerous stocks (e.g., all 20+ securities in an economic sector) by creating a **dynamic grid of subplots**. You will learn how to read every individual stock file from a folder and dynamically calculate the required number of rows and columns to fit all plots onto a single, organized figure. This is crucial for comparing the performance of many stocks at a glance. ### ๐ŸŽฏ Key Learning Outcomes: 1. **Dynamic Subplot Sizing:** Use the **`math` module** and the `plt.subplots` function to calculate the exact number of rows needed for your grid, regardless of how many stock files are in the folder. 2. **File Iteration:** Loop through all individual stock data files in a folder and plot each one sequentially. 3. **Relative Performance:** Transform the raw closing prices into **relative performance** data (normalized to the starting price) for a meaningful comparison. 4. **Matplotlib Formatting:** Apply advanced formatting using **`matplotlib.ticker.PercentFormatter`** to display the y-axis as clean percentages. ### โฑ๏ธ Video Chapters (Jump Ahead!): 0:00 - Introduction & Review (Goal: Plot all stocks in one figure) 0:40 - Reading All Files & Importing the `math` Module 1:06 - **Dynamic Subplots Setup** (Using `math.ceil` for grid dimensions) 1:49 - Nested For Loop for Plotting to the Correct Axes 2:20 - Reading CSV, Calculating **Relative Performance** 2:30 - Plotting to the Correct Axes (`ax[row, col]`) 2:46 - Formatting Y-Axis as **Percent** with `matplotlib.ticker` 3:17 - Handling Errors/End of Data with `try/except` Block 3:40 - Testing the Function (Plotting the Energy Sector Grid) 4:25 - Preview of Part 8: More cuts of data from the EOD API ### ๐Ÿ”— Course

Original Description

@MattMacarty ## ๐Ÿ Python Matplotlib: Plot Performance Grid of Multiple Stocks with Dynamic Subplots | Part 7 Welcome to Part 7 of the **Python Stock Analysis Course**! This video focuses on **advanced data visualization** using **Matplotlib**. We solve the challenge of plotting the relative performance of numerous stocks (e.g., all 20+ securities in an economic sector) by creating a **dynamic grid of subplots**. You will learn how to read every individual stock file from a folder and dynamically calculate the required number of rows and columns to fit all plots onto a single, organized figure. This is crucial for comparing the performance of many stocks at a glance. ### ๐ŸŽฏ Key Learning Outcomes: 1. **Dynamic Subplot Sizing:** Use the **`math` module** and the `plt.subplots` function to calculate the exact number of rows needed for your grid, regardless of how many stock files are in the folder. 2. **File Iteration:** Loop through all individual stock data files in a folder and plot each one sequentially. 3. **Relative Performance:** Transform the raw closing prices into **relative performance** data (normalized to the starting price) for a meaningful comparison. 4. **Matplotlib Formatting:** Apply advanced formatting using **`matplotlib.ticker.PercentFormatter`** to display the y-axis as clean percentages. ### โฑ๏ธ Video Chapters (Jump Ahead!): 0:00 - Introduction & Review (Goal: Plot all stocks in one figure) 0:40 - Reading All Files & Importing the `math` Module 1:06 - **Dynamic Subplots Setup** (Using `math.ceil` for grid dimensions) 1:49 - Nested For Loop for Plotting to the Correct Axes 2:20 - Reading CSV, Calculating **Relative Performance** 2:30 - Plotting to the Correct Axes (`ax[row, col]`) 2:46 - Formatting Y-Axis as **Percent** with `matplotlib.ticker` 3:17 - Handling Errors/End of Data with `try/except` Block 3:40 - Testing the Function (Plotting the Energy Sector Grid) 4:25 - Preview of Part 8: More cuts of data from the EOD API ### ๐Ÿ”— Course
Watch on YouTube โ†— (saves to browser)
Sign in to unlock AI tutor explanation ยท โšก30

Related AI Lessons

โšก
Surviving the Data Science Behavioral Interview
Learn to ace data science behavioral interviews with confidence using three key tips
Towards Data Science
โšก
Before I needed it, no one told me that "legacy tape management" was an entire industry.
Learn about legacy tape management and its importance in data migration, especially when dealing with large-scale tape collections
Reddit r/artificial
โšก
Top 5 DBMS Concepts (2026) | Perfectnotes
Learn the top 5 DBMS concepts to manage data efficiently in applications
Medium ยท Data Science
โšก
The Nervous System of the Telco: Unlocking the Real-Time Power of the Network Element Interfacesโ€ฆ
Unlock the power of network element interfaces to enable real-time insights in telco operations
Medium ยท Data Science

Chapters (10)

Introduction & Review (Goal: Plot all stocks in one figure)
0:40 Reading All Files & Importing the `math` Module
1:06 **Dynamic Subplots Setup** (Using `math.ceil` for grid dimensions)
1:49 Nested For Loop for Plotting to the Correct Axes
2:20 Reading CSV, Calculating **Relative Performance**
2:30 Plotting to the Correct Axes (`ax[row, col]`)
2:46 Formatting Y-Axis as **Percent** with `matplotlib.ticker`
3:17 Handling Errors/End of Data with `try/except` Block
3:40 Testing the Function (Plotting the Energy Sector Grid)
4:25 Preview of Part 8: More cuts of data from the EOD API
Up next
Spreadsheet Guy Meets the CFO: "Define How Much"
Digital Transformation with Eric Kimberling
Watch โ†’