开发者

How can I print a plot in matplotlib either from the plot window or with a command?

开发者 https://www.devze.com 2023-04-05 09:08 出处:网络
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 automat

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

0

精彩评论

暂无评论...
验证码 换一张
取 消