Skip to content

Instantly share code, notes, and snippets.

@windstriver
Created January 19, 2017 12:58
Show Gist options
  • Save windstriver/b84040ad680f18b0f33fad736f631600 to your computer and use it in GitHub Desktop.
Save windstriver/b84040ad680f18b0f33fad736f631600 to your computer and use it in GitHub Desktop.
A python script to save matplotlib plot to pdf file.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
x = np.random.randn(1000)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.hist(x, 100)
ax.set_title('Normal distribution with $\mu=0, \sigma=1$')
with PdfPages('foo.pdf') as pdf:
pdf.savefig(fig)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment