x 刻度标签的间隔要关闭

x 刻度标签的间隔要关闭

我对 x 刻度标签的间隔有些困惑。我有两个标签,所以文本相互重叠。

我的代码如下:

\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}

结果如下:

在此处输入图片描述

如果间隔要关闭,刻度应该自动减少,不是吗?如果间隔减小,绘图的准确性会变差吗?

答案1

为了与 Thruston 的 Metapost 解决方案进行比较,以下是使用 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}

答案2

这并不能直接回答有关 Pgfplots 的问题,但如果你真的想完全控制你的优雅情节,有时值得“手动”完成元帖子。这是您的图表的一个版本,仅供参考和比较。

在此处输入图片描述

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.

相关内容