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 then print,but I am looking for something more auto
Solution 1:
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)))
Solution 2:
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
Post a Comment for "How Can I Print A Plot In Matplotlib Either From The Plot Window Or With A Command?"