python save figure as pdf 1

python save figure as pdf

import matplotlib.pyplot as plt

f = plt.figure()
plt.plot(range(10), range(10), "o")
plt.show()

f.savefig("foo.pdf", bbox_inches='tight')

Here is what the above code is Doing:
1. Create a figure object
2. Plot something
3. Show the plot
4. Save the figure to a file

The last line is the one that’s important. The bbox_inches=’tight’ is
basically a hack to make sure that the figure is saved with minimal
whitespace around it.

Similar Posts