Course Hive
Search

Welcome

Sign in or create your account

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

Python Quantitative Finance & Stock Analysis Course (Pandas, NumPy, SciPy) ๐Ÿ - Python Matplotlib: Plot Performance Grid of Multiple Stocks with Dynamic Subplots | Part 7 ๐Ÿ–ผ๏ธ

Master Python for Stock Analytics: From Data Download to Custom Analysis Tools

5.0 (1)
14 learners

What you'll learn

Analyze and filter stock data using Python and Pandas.
Download and manage historical stock data in CSV format.
Visualize stock performance with plots and correlation matrices.
Create and install a custom stock analysis library with Python.

This course includes

  • 1.5 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

@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 Series & Resources: * **Part 6 (Export to Excel):** [https://youtu.be/Ox7qVlfNYNE](https://youtu.be/Ox7qVlfNYNE) * **Get the Code:** https://github.com/mjmacarty/python-stock-analysis ***Disclaimer: This video is for educational purposes only. The information provided should not be construed as investment advice. *** \#Matplotlib \#PythonSubplots \#PerformanceGrid \#DataVisualization \#RelativePerformance \#PythonForFinance \#StockAnalysis \#DynamicPlotting \#Part7

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere