[python] Saving multiple graphs as one pdf

<문법>/파이썬|2021. 12. 27. 15:10
반응형

참조 : https://stackoverflow.com/questions/11328958/save-multiple-plots-in-a-single-pdf-file

 

Save multiple plots in a single PDF file

plotting module def plotGraph(X,Y): fignum = random.randint(0,sys.maxint) plt.figure(fignum) ### Plotting arrangements ### return fignum main module import matplotlib.pyplot as plt...

stackoverflow.com

 

with PdfPages('multipage_pdf.pdf') as pdf:
  # 그래프1 
  plt.figure(figsize=(3, 3))
  plt.plot(range(7), [0,1,2,3,4,5,6], 'r-o')
  plt.title('graph one')
  pdf.savefig()  # saves the current figure into a pdf page

  # 그래프2
  plt.figure(figsize=(3, 3))
  plt.plot(range(7), [0,1,2,3,4,5,6], 'r-o')
  plt.title('graph two')
  pdf.savefig()  # saves the current figure into a pdf page
  # plt.close() 그래프 출력안할거면 사용
반응형

댓글()