title: Showing and saving PGF plots from Jupyter Notebook
body: <p>I have prepared a Jupyter Notebook with a number of matplotlib plots. Now I would like to save plots to PGF format, so I can reuse them in LaTeX. I have followed <a href="https://timodenk.com/blog/exporting-matplotlib-plots-to-latex/" rel="noreferrer">this blog post</a> to implement that idea. </p>
  
  <p>Unfortunately, if I configure matplotlib to generate PGF files they are not shown in the notebook. If I disable matplotlib to generate PGF files plots are shown but PGF files are not generated. How can I have both?</p>
  
  <p>Here's minimal example to reproduce the problem:</p>
  
  <pre><code># Test if integration between python and latex works fine
  import subprocess; subprocess.check_call(["latex", "-help"])
  
  # Configure matplotlib to generate PGF files
  import matplotlib
  import matplotlib.pyplot as plt 
  matplotlib.use("pgf")
  matplotlib.rcParams.update({
      "pgf.texsystem": "pdflatex",
      'font.family': 'serif',
      'text.usetex': True,
      'pgf.rcfonts': False,
  })
  
  # Prepare simple plot
  import pandas as pd
  df = pd.DataFrame({
       'length': [1.5, 0.5, 1.2, 0.9, 3],
       'width': [0.7, 0.2, 0.15, 0.2, 1.1]
       }, index= ['pig', 'rabbit', 'duck', 'chicken', 'horse'])
  hist = df.hist(bins=3)
  
  # Save the plot to PGF file
  plt.savefig('histogram.pgf')
  </code></pre>
  
  <p>Here's the output for <em>enabled</em> configuration of matplotlib. <code>histogram.pgf</code> file is generated and saved, but plot is not shown.</p>
  
  <p><a href="https://i.stack.imgur.com/27KS2.png" rel="noreferrer"><img src="https://i.stack.imgur.com/27KS2.png" alt="With configuration enabled"></a></p>
  
  <p>Here's example of when disabling matplotlib configuration for PGF. Plot is shown, but generated <code>histogram.pgf</code> file is empty --- does not contain the plot.</p>
  
  <p><a href="https://i.stack.imgur.com/DEZni.png" rel="noreferrer"><img src="https://i.stack.imgur.com/DEZni.png" alt="enter image description here"></a></p>