Save a matplotlib figure as PDF

import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

# sample data
x = np.arange(120) * np.pi / 30
y = np.sin(x)

fig = plt.figure()
ax = fig.add_subplot()
ax.plot(y)

with PdfPages('sample.pdf') as pdf:
    pdf.savefig(fig)

コメント

タイトルとURLをコピーしました