summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2009-11-16 10:16:54 +0000
committerAlberto Ruiz <aruiz@um.es>2009-11-16 10:16:54 +0000
commit9330e2d066e5fe661d956e0507c7cee4ed19b769 (patch)
tree536d6467abcf17d6804b46bd476be188e049c62f /lib
parentca67378bef1b0e4e76b4421786a846956c47f380 (diff)
gnuplotpdf
Diffstat (limited to 'lib')
-rw-r--r--lib/Graphics/Plot.hs42
1 files changed, 41 insertions, 1 deletions
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(
24 24
25 matrixToPGM, imshow, 25 matrixToPGM, imshow,
26 26
27 gnuplotX 27 gnuplotX, gnuplotpdf
28 28
29) where 29) where
30 30
@@ -163,3 +163,43 @@ imshow :: Matrix Double -> IO ()
163imshow m = do 163imshow m = do
164 system $ "echo \""++ matrixToPGM m ++"\"| display -antialias -resize 300 - &" 164 system $ "echo \""++ matrixToPGM m ++"\"| display -antialias -resize 300 - &"
165 return () 165 return ()
166
167----------------------------------------------------
168
169gnuplotpdf :: String -> String -> [([[Double]], String)] -> IO ()
170gnuplotpdf title command ds = gnuplot (prelude ++ command ++" "++ draw) >> postproc where
171 prelude = "set terminal epslatex color; set output '"++title++".tex';"
172 (dats,defs) = unzip ds
173 draw = concat (intersperse ", " (map ("\"-\" "++) defs)) ++ "\n" ++
174 concatMap pr dats
175 postproc = do
176 system $ "epstopdf "++title++".eps"
177 mklatex
178 system $ "pdflatex "++title++"aux.tex > /dev/null"
179 system $ "pdfcrop "++title++"aux.pdf > /dev/null"
180 system $ "mv "++title++"aux-crop.pdf "++title++".pdf"
181 system $ "rm "++title++"aux.* "++title++".eps "++title++".tex"
182 return ()
183
184 mklatex = writeFile (title++"aux.tex") $
185 "\\documentclass{article}\n"++
186 "\\usepackage{graphics}\n"++
187 "\\usepackage{nopageno}\n"++
188 "\\usepackage{txfonts}\n"++
189 "\\renewcommand{\\familydefault}{phv}\n"++
190 "\\usepackage[usenames]{color}\n"++
191
192 "\\begin{document}\n"++
193
194 "\\begin{center}\n"++
195 " \\input{./"++title++".tex}\n"++
196 "\\end{center}\n"++
197
198 "\\end{document}"
199
200 pr = (++"e\n") . unlines . map (unwords . (map show))
201
202 gnuplot cmd = do
203 writeFile "gnuplotcommand" cmd
204 system "gnuplot gnuplotcommand"
205 system "rm gnuplotcommand"