
insertion.dat
対数スケールを使用して、いくつかのソート アルゴリズムの時間計算量をプロットしようとしています。次の情報を含むテキスト ファイルからデータを取得しています。
x y
0 0
10 0.002
100 0.019
1000 1.636
5000 42.735
10000 167.950
そして、次のコードを使用してそれを実装しようとしています。
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=15cm,
height=7cm,
axis x line=center,
axis y line=center,
ytick={0,10,100,1000},
xtick={0,10, 1000, 5000,10000},
ymode=log, xmode=log,
xlabel={\texttt{L}},
ylabel={Time (ms)},
xlabel style={right},
ylabel style={above},
xmin=0,
xmax=15000,
ymin=0,
ymax=2000]
\addplot[smooth,red,thick] table[y expr=\thisrow{y}/0.95] {insertion.dat};
\end{axis}
\end{tikzpicture}
\end{document}
しかし、私が得た結果は次のようになります:
軸はどうなっているのでしょうか? どうすれば修正できますか?
答え1
主な間違いは、 を使用することです。axis y line=center
これは、軸が を通る0
か、log 軸の場合は を通ることを意味します1
。これを に変更しaxis y line=left
、少なくともxmin
値にすると、目的の結果が得られる可能性があります。ただし、 はylabel
(再び) 中央の左側に配置されます。これは、 キーを使用して変更できますylabel style
。
\begin{filecontents}{insertion.dat}
x y
10 0.002
100 0.019
1000 1.636
5000 42.735
10000 167.950
\end{filecontents}
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmode=log,
ymode=log,
%
width=15cm,
height=7cm,
axis x line=center,
axis y line=left, % <-- `center' confuses PGFPlots on a log axis
xmin=5,
xmax=15000,
ymin=1e-3,
ymax=2000,
xlabel={\texttt{L}},
ylabel={Time (ms)},
xlabel style={right},
ylabel style={
at={(rel axis cs:0,1)},
rotate=-90,
anchor=south,
},
]
\addplot [smooth,red,thick,mark=*]
table [y expr=\thisrow{y}/0.95] {insertion.dat};
\end{axis}
\end{tikzpicture}
\end{document}