From 9330e2d066e5fe661d956e0507c7cee4ed19b769 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Mon, 16 Nov 2009 10:16:54 +0000 Subject: gnuplotpdf --- lib/Graphics/Plot.hs | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Graphics/Plot.hs b/lib/Graphics/Plot.hs index e6a9098..b3cf9d9 100644 --- a/lib/Graphics/Plot.hs +++ b/lib/Graphics/Plot.hs @@ -24,7 +24,7 @@ module Graphics.Plot( matrixToPGM, imshow, - gnuplotX + gnuplotX, gnuplotpdf ) where @@ -163,3 +163,43 @@ imshow :: Matrix Double -> IO () imshow m = do system $ "echo \""++ matrixToPGM m ++"\"| display -antialias -resize 300 - &" return () + +---------------------------------------------------- + +gnuplotpdf :: String -> String -> [([[Double]], String)] -> IO () +gnuplotpdf title command ds = gnuplot (prelude ++ command ++" "++ draw) >> postproc where + prelude = "set terminal epslatex color; set output '"++title++".tex';" + (dats,defs) = unzip ds + draw = concat (intersperse ", " (map ("\"-\" "++) defs)) ++ "\n" ++ + concatMap pr dats + postproc = do + system $ "epstopdf "++title++".eps" + mklatex + system $ "pdflatex "++title++"aux.tex > /dev/null" + system $ "pdfcrop "++title++"aux.pdf > /dev/null" + system $ "mv "++title++"aux-crop.pdf "++title++".pdf" + system $ "rm "++title++"aux.* "++title++".eps "++title++".tex" + return () + + mklatex = writeFile (title++"aux.tex") $ + "\\documentclass{article}\n"++ + "\\usepackage{graphics}\n"++ + "\\usepackage{nopageno}\n"++ + "\\usepackage{txfonts}\n"++ + "\\renewcommand{\\familydefault}{phv}\n"++ + "\\usepackage[usenames]{color}\n"++ + + "\\begin{document}\n"++ + + "\\begin{center}\n"++ + " \\input{./"++title++".tex}\n"++ + "\\end{center}\n"++ + + "\\end{document}" + + pr = (++"e\n") . unlines . map (unwords . (map show)) + + gnuplot cmd = do + writeFile "gnuplotcommand" cmd + system "gnuplot gnuplotcommand" + system "rm gnuplotcommand" -- cgit v1.2.3