7

I am spawning a .eps file with octave by using this .m file:

function dummy
xlim([0 81]);
x = [0:0.01:81];
y=x.^0.5+x.^0.4+x.^0.3+x.^0.2+x.^0.1;
plot (x,y*1.85,"-;aaaa;",'linewidth',2,x,y*1.00,"-;bbbb;",'linewidth',2,x,y*1.25,"-;cccc;",'linewidth',2,x,x/2,"-;dddd;",'linewidth',2);
legend ("location", "northwest");
xlabel ("kkkk");
ylabel ("yyyy");
set (gca (), "xtick",[]);
set (gca (), "ytick",[]);
set (gca (), "fontname","DejaVuSans");
print('-dtex', 'dummy.tex');
endfunction

and including it with this LaTeX "container":

\documentclass[12pt]{article}
\usepackage{psfrag}
\usepackage[dvips]{graphicx,color}
\thispagestyle{empty}

    % You can run this by typing the following commands:
    %    latex 2dplot.tex
    %    dvips -o 2dplot.ps 2dplot.dvi

\begin{document}

% The syntax of the "psfrag" command is:
%    \psfrag{tag}[<posn>][<psposn>][<scale>][<rot>]{replacement}
% See the file pfgguide.ps for full documentation.

\begin{figure}
\psfrag{aaaa}{\small{$y$}}
\psfrag{bbbb}{\small{$s_1 \cdot y$}}
\psfrag{cccc}{\small{$s_2 \cdot y$}}
\psfrag{dddd}{\small{$k(\Sigma + n + g)$}}
\psfrag{kkkk}{\small{$k$}}
\psfrag{yyyy}{\small{$y$}}
\includegraphics{dummy.eps}
\end{figure}


\end{document}

But the psfrag replacements show up at bottom left corner of the page.
Running latex ./dummy.tex does not yield any errors.

Martin Scharrer
  • 262,582
drahnr
  • 215

3 Answers3

4

The replacements not showing on the actual picture are OK. From the psfrag manual:

When viewing the output with a DVI previewer such as dviwin or xdvi, a vertical list of the replacements will be placed on the left side of each figure. This list allows you to check the typesetting of your replacements; it disappears in the final PostScript version. Unfortunately, DVI drivers are incapable of placing the PSfrag replacements on top of the figure, so for that you will need to print it or use a PostScript previewer like GhostView

You should convert your dvi to ps or pdf or print it in order for the replacements to apply.

fabikw
  • 6,203
  • You'll also see the same behavior when using TikZ or pstricks to draw images with TeX text included in the image. A DVI previewer won't position the text properly, but a postscript or PDF version will be fine. This is due to the limitations of the DVI previewers. – Ken Bloom May 05 '11 at 15:08
2

As for an alternative to Octave, here is how I would do in R:

x <- seq(0, 81, by=.01)
y <- x^.5+x^.4+x^.3+x^.2+x^.1
dat <- data.frame(x, y1=y*1.85, y2=y, y3=y*1.25, y4=x/2)

library(lattice)
lp <- xyplot(y1+y2+y3+y4~x, dat, type="l", xlab="k", ylab="y",
             main="Tour title here",
             col = c('blue', 'red', 'green', 'cyan'),
             key=list(x=0.05, y=0.95, text=list(c(expression(y), 
                                                  expression(s[1] %.% y), 
                                                  expression(s[2] %.% y), 
                                                  expression(k(Sigma + n + g)))),
                      lines=list(lty=1, col=c('blue','red','green','cyan'))))

It can be saved as PDF with

pdf("yourfilename.pdf", width=5, height=5)
print(lp)
dev.off()

or quite in the same manner with the postscript() function for EPS output.

Here is the result:

enter image description here

chl
  • 8,890
  • ocatve is not capable of inserting greek letters and fun, therefore I wanted to replace the dummy labels aaaa, bbbb and so on with the correct greek formule – drahnr May 05 '11 at 12:58
  • @drahnr I missed that point. Would you like me to give you the R syntax for producing such a plot? – chl May 05 '11 at 13:02
  • even if I use your print(...) , I still get the PSfrag replacments all rendered at the bottom right of the dvi and the legend gets not adjusted as desired – drahnr May 05 '11 at 13:06
  • give me whatever you have :> I am thankful for everything, maybe point me to a R howto :) thank you – drahnr May 05 '11 at 13:06
  • @drahnr When I generated the pdf, I removed every psfrag commands. – chl May 05 '11 at 13:07
  • @drahnr Done. I hope you'll manage to achieve what you want with the above R code. You'll find more help on R plotting on Quick-R or Graphics with R, for a first start. – chl May 05 '11 at 13:46
  • can I somehow hide the scale and the dics at the axes? – drahnr May 05 '11 at 13:49
  • @drahnr Sure. Add scales=list(alternating=0, tck=c(0,0)) in the arguments. – chl May 05 '11 at 14:17
  • @chl: If you figure out that your original answer was wrong (I'm not saying it is), simply replace it with the correct one. There is no reason to keep it around and just append the correct one. The history of your edits are saved so nothing is getting lost. – Martin Scharrer May 05 '11 at 14:25
  • @Martin Now that I see @fabikw provided a more relevant answer (it didn't work for me, though), I think I will just delete the first part of my response, and make this a CW answer as this now has (obviously) nothing to do with the question :-) – chl May 05 '11 at 14:29
  • 1
    @drahnr While we're in (and because I read another comment of yours), you can change line thickness with lwd= ($>1$ means larger) and line type with lty= (1=solid, 2=dashed, 3=dotted, 4=dash-and-dot). It might help if this is for a BW paper. Be sure to add this in both the legend (inside the key list) and the call to xyplot. Should you want to add a grid layout, use type=c("l", "g"). Good luck! – chl May 05 '11 at 16:14
0

Generally, I'd be inclined to alter a graphic item by altering the code that created it. If that cannot be done, I'd use inkscape on it. These two options yield a graphic that can be used in any application (e.g. presentation application, web application), and not just in latex. So, heresy that this may be in this group, I'd advise dropping your work with psfrag, seeing as you've had difficulties.

dank
  • 2,189
  • 3
    Postprocessing with inkscape is uggly, in case the grpahs change in the future I'll have to redo it anytime even only a tiny bit changes. Not an option. It is for a paper so.. – drahnr May 05 '11 at 13:00