# Chapter 12: Data Visualization with Python
# Fundamentals of Python for Financial Econometrics - Data Visualization with Python
# Dataset: Ceteris Lab teaching sample

# Data Visualization with Python
#
# **Opening question:** What should a figure reveal that a table or coefficient cannot show as clearly?

# %% Cell 2
import matplotlib.pyplot as plt
import pandas as pd

series = pd.Series([1.2, 1.4, 1.3, 1.6], index=pd.date_range("2026-01-01", periods=4, freq="MS"))
fig, ax = plt.subplots()
ax.plot(series.index, series.values, marker="o")
ax.set(title="Illustrative Monthly Index", xlabel="Month", ylabel="Index points")
fig.tight_layout()
plt.close(fig)
print(len(series))

# **Interpretation check:** Interpretation. The code creates a reusable figure object and labels both the time dimension and the unit.

# %% Cell 4
import numpy as np
import matplotlib.pyplot as plt

rng = np.random.default_rng(12)
values = rng.standard_t(df=5, size=1_000)
fig, ax = plt.subplots()
ax.hist(values, bins=35, density=True)
ax.set(title="Heavy-tailed simulated observations", xlabel="Value", ylabel="Density")
plt.close(fig)
print(round(values.std(), 3))

# **Interpretation check:** Interpretation. The histogram reveals tails and concentration that a standard deviation alone cannot convey.

# %% Cell 6
import matplotlib.pyplot as plt
import pandas as pd
fig, ax = plt.subplots()
ax.plot(series.index, series.values, marker="o")
ax.set(title="Illustrative Monthly Index", xlabel="Month", ylabel="Index points")
fig.tight_layout()

# Verified source output
#
# ```text
# 4
# ```
#
# ```text
# 1.263
# ```
