2

I have some trouble with the interval of the x tick labels. I have two much labels so the text overlap each other.

My code is following:

\begin{figure}
\begin{tikzpicture}
\begin{axis}[
    width=0.8\linewidth,
    xlabel={Anzahl der Prozessoren},
    ylabel={Speedup},
    domain = 1:4096,
    xmin=1, xmax=4096,
    ymin=0, ymax=30,
    xmode = log,
    log basis x={2},
    xticklabel=\pgfmathparse{2^\tick}\pgfmathprintnumber{\pgfmathresult},
    legend pos = north west
]
\addplot [black, very thick, dashed]{
1/((1-0.5) + 0.5/x)
};
\addplot [black, very thick, dotted]{
1/((1-0.8) + 0.8/x)
};
\addplot [black, very thick, loosely dotted]{
1/((1-0.9) + 0.9/x)
};
\addplot [black, very thick, solid]{
1/((1-0.95) + 0.95/x)
};;     
\legend{%
P = 50\%,
P = 80\%,
P = 90\%,
P = 95\%,
}
\end{axis}
\end{tikzpicture}
\caption{Speedup nach Amdahla'sches Gesetz}
\label[figure]{fig:amdahls_law_speedup}
\end{figure}

Here is a result of it:

enter image description here

The ticks should automatically decrease if the interval is to close, shouldn't it? If the interval is decreased, will the accuracy of the plot worse?

Burak
  • 401
  • 1
  • 4
  • 11
  • 3
    When I put your code into a small document, I don't get that output, I only get labels for 2, 8, 32, etc. Could you turn your code into a minimal compilable document (starting from \documentclass) that reproduces the problem. – Jake Sep 05 '14 at 17:33
  • 1
    Pgfplots will adjust the number and spacing of the ticks automatically depending on the width of the figure. Maybe you are at some critical page width, that's making the automatic spacing code get in a muddle. Try it with a different width? (and please do update your example to be a fully compilable minimal document as requested). – Thruston Sep 05 '14 at 18:02
  • I solved my problem: I set width=\textwidth and used a \scaleobx{0.8} for the tikzpicutre to scale it back. The legends are smaller but it worked. – Burak Sep 11 '14 at 11:28

2 Answers2

6

Just for comparison with Thruston's Metapost solution, here's how you would get that chart using PGFPlots:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    width=\linewidth,
    xlabel={Anzahl der Prozessoren},
    ylabel={Speedup},
    domain = 1:4096,
    xmin=1, xmax=4096,
    ymin=0, ymax=22,
    ytick={0,5,...,25},
    /pgf/number format/1000 sep={},
    xmode = log,
    log basis x={2},
    xticklabel=\pgfmathparse{2^\tick}\pgfmathprintnumber{\pgfmathresult},
    clip=false,
    every axis plot post/.style={red!75!black, very thick},
    /tikz/plot label/.style={black, anchor=west}
]
\addplot [dashed]{ 1/((1-0.5) + 0.5/x) } node [plot label] {$P=0.5$};
\addplot [dotted]{ 1/((1-0.8) + 0.8/x) } node [plot label] {$P=0.8$};
\addplot [loosely dotted]{ 1/((1-0.9) + 0.9/x) } node [plot label] {$P=0.9$};
\addplot [solid]{ 1/((1-0.95) + 0.95/x) } node [plot label] {$P=0.95$};     

\end{axis}
\end{tikzpicture}
\end{document}
Jake
  • 232,450
2

This does not directly answer the question about Pgfplots, but if you really want full control over your elegant plot, sometimes it's worth doing it "by hand" in Metapost. Here's a version of your graph, just for interest and comparison.

enter image description here

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);

% u = x-unit, v = y-unit spacing
u = 1cm;
v = 4mm;
xmax = 12;
ymax = 24;

% draw the function curves and label them (instead of a legend)
path p[];
forsuffixes i=0.5,0.8,0.9,0.95:
  p[i] = ( (0,1) for j=1 upto xmax: .. (j,1/((1-i)+i/(2**j))) endfor ) xscaled u yscaled v;
  draw p[i] withpen pencircle scaled 1 dashed withdots scaled (1/i-.4) withcolor .67 red;
  write "label.rt(btex $P=" & decimal i & "$ etex, point infinity of p[" & decimal i & "]);" to ".mplabels";
endfor
write EOF to ".mplabels";
input .mplabels

% y-axis
for i=0 step 5 until ymax-1: 
  label.lft(decimal i, (0,i*v)); 
  draw (origin -- (+u/5 ,0)) shifted (0,     i*v) withcolor .4 white;
  draw (origin -- (-u/5 ,0)) shifted (xmax*u,i*v) withcolor .4 white;
endfor

% x-axis
for i=1 step 1 until xmax-1:
  label.bot(decimal floor(0.5+2**i), (i*u,0));
  draw (origin -- (0,+u/5)) shifted (i*u,0)   withcolor .4 white;
  draw (origin -- (0,-u/5)) shifted (i*u,ymax*v) withcolor .4 white;
endfor

% fancy frame
draw unitsquare xscaled (xmax*u) yscaled (ymax*v) withpen pensquare scaled 1.4;
draw unitsquare xscaled (xmax*u) yscaled (ymax*v) withcolor background;

% axis labels
label.bot(btex Number of Processors etex, (xmax*u/2,-1.6v));
label.lft(btex Speed up etex rotated 90, (-1.6v,ymax*v/2));

% some more space around everything
setbounds currentpicture to (
          llcorner currentpicture shifted (-8,-8) --
          lrcorner currentpicture shifted (+8,-8) --
          urcorner currentpicture shifted (+8,+8) --
          ulcorner currentpicture shifted (-8,+8) --
          cycle);

endfig;
end.
Thruston
  • 42,268