Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 automated.Thanks.

like image 892
IordanouGiannis Avatar asked Sep 14 '11 16:09

IordanouGiannis


People also ask

How do I show multiple plots in matplotlib?

To draw multiple plots using the subplot() function from the pyplot module, you need to perform two steps: First, you need to call the subplot() function with three parameters: (1) the number of rows for your grid, (2) the number of columns for your grid, and (3) the location or axis for plotting.

How do I make two matplotlib plots in one window?

In Matplotlib, we can draw multiple graphs in a single plot in two ways. One is by using subplot() function and other by superimposition of second graph on the first i.e, all graphs will appear on the same plot.


1 Answers

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)))
like image 124
unutbu Avatar answered Oct 17 '22 22:10

unutbu