How can I print a plot in matplotlib either from the plot window or with a command?
is there a way to print a plot from matplotlib,either with a command or from the plot window itself ? I know i could save it and the开发者_开发知识库n print,but I am looking for something more automated.Thanks.
You could save the figure as a pdf, then use subprocess
to print the pdf. On *nix, lpr
could be used:
import matplotlib.pyplot as plt
import numpy as np
import subprocess
import shlex
n=20
x=np.linspace(0,np.pi,n)
y=np.sin(x)
plt.plot(x,y)
fname='/tmp/test.pdf'
plt.savefig(fname)
proc=subprocess.Popen(shlex.split('lpr {f}'.format(f=fname)))
From the plot window itself, there is a "save" toggle button, in the shape of a disk on the right side of the row of buttons.
From the command line or script, you can use:
pylab.savefig("directory/filename.pdf")
Look here for some of the details:
http://matplotlib.sourceforge.net/faq/howto_faq.html#plotting-howto
精彩评论