# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Saving plots using PdfPages
#
# In this tutorial, we create a parabola. On each consecutive page of the pdf, we plot a growing range of this parabola. As you cycle through  the pages, the parabola seems to grow

# +
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

parabola = [x ** 2 for x in range(100)]
pp = PdfPages("growingParabola.pdf")

for i in range(1, len(parabola)):
    fig, ax = plt.subplots(figsize = (40,20))
    ax.set_ylim(bottom = 0, top = parabola[-1])
    ax.set_xlim(left = 0, right = len(parabola))
    plt.plot(parabola[:i], linewidth = 5)
    pp.savefig(fig, bbox_inches = "tight")
    plt.close()  
pp.close()

StarcoderdataJupyterScriptsDedupFiltered