import matplotlib.pyplot as plt
import re

# --- Step 1: Read pattern from file ---
with open("pattern.txt", "r") as f:
    text_from_file = f.read().strip()   # e.g., "Forecast for YYYY-MM"

# --- Step 2: Substitute placeholders ---
year = 2025
month = "Sep"

# Option A: simple replace
title_str = text_from_file.replace("YYYY", str(year)).replace("MM", month)

# Option B: regex (if more complex)
# title_str = re.sub(r"YYYY", str(year), text_from_file)
# title_str = re.sub(r"MM", month, title_str)

# --- Step 3: Use in pyplot ---
plt.plot([1,2,3], [2,4,6])
plt.title(title_str, fontsize=14)
plt.show()
If pattern.txt contains:

rust
Copy code
Forecast for YYYY-MM
then the title will become:

yaml
Copy code
Forecast for 2025-Sep

