diff options
Diffstat (limited to 'lib/Graphics/Plot.hs')
-rw-r--r-- | lib/Graphics/Plot.hs | 42 |
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 () | |||
163 | imshow m = do | 163 | imshow 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 | |||
169 | gnuplotpdf :: String -> String -> [([[Double]], String)] -> IO () | ||
170 | gnuplotpdf 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" | ||