title: Plot pandas columns with secondary y -axis and saving charts to a single pdf
body: <p>I am trying to create multiple time-series plots using data in a Pandas DataFrame columns. I want to save all these charts to a single pdf file. The challenge is that these charts all have a secondary y-axis which has a different scale (see Col Z below). I have seen examples of saving multiple charts to pdf, and examples of plotting a singe chart with a secondary y-axis, but don't know how to combine the two. My actual DataFrame has 50 columns, so doing it manually would be tedious. Thanks in advance.</p>
  
  <p>Here is what I tried:</p>
  
  <pre><code>df1 = pd.DataFrame(np.random.rand(10, 4))
  df1.columns = ['A', 'B', 'C', 'Z']
  date_range = pd.date_range('1/31/2011', periods=10, freq='M')
  df1['Z'] = 100*df1['Z']
  df1.plot(kind='line', subplots=True, secondary_y=['Z'])
  #
  
  import matplotlib.backends.backend_pdf
  pdf = matplotlib.backends.backend_pdf.PdfPages("output.pdf")
  plt.figure()
  for cols in df1.columns:
      df1.plot(y=cols, secondary_y=['Z'])
      pdf.savefig(fig)
  pdf.close()
  </code></pre>