나는 pgf
즉시 플롯을 생성하고 y ticks
있으며 모든 x ticks
. MWE는 다음과 같습니다.
\documentclass[10pt]{article}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{amssymb}
\usepackage{pgfplotstable}
\usepackage[active, pdftex, tightpage]{preview}
\PreviewEnvironment[{[]}]{tikzpicture}
\setlength\PreviewBorder{2mm}
\begin{filecontents}{PJxpGrZtwos.tex.dat}
N f M
1024 3.407938e+01 25
1536 1.339487e+01 20
2048 1.139487e+01 19
3072 8.351236e+00 14
4049 6.466788e+00 13
6144 4.466788e+00 11
\end{filecontents}
\pgfkeys{/pgf/fpu=true}
\pgfplotstableread{PJxpGrZtwos.tex.dat}\loadedtable
\pgfplotstablegetelem{0}{N}\of{\loadedtable}
\let\relativeTo\pgfplotsretval
\pgfplotstablegetelem{0}{f}\of{\loadedtable}
\let\f\pgfplotsretval
\pgfplotstablecreatecol[create col/expr={\f / \thisrow{f}}]{f-relative}\loadedtable
\pgfkeys{/pgf/fpu=false}
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}[axis y line*=left, legend pos=south east,xlabel={N},xtick=data, xticklabels from table={\loadedtable}{N},ytick=data, yticklabel=\pgfmathparse{exp(\tick)}\pgfmathprintnumber{\pgfmathresult}, ylabel ={$\dfrac{f(\pgfmathprintnumber\relativeTo)}{f(N)}$}]
\addplot[black] table[x=N, y expr=\thisrow{N}/\relativeTo] {\loadedtable};
\addplot[blue, mark=*] table[x=N, y=f-relative] {\loadedtable};
\legend{{Linear progression},}
\end{loglogaxis}
\begin{semilogxaxis}[ymin = 5, ytick={10, 15, ..., 30}, ymax = 35, axis x line=none,ylabel={\# M}, axis x line=none, axis y line*=right, ylabel near ticks=right, yticklabel pos=right]
\addplot[red, dotted, mark=x, mark options={solid}] table[x=N, y=M] {\loadedtable};
\end{semilogxaxis}
\end{tikzpicture}
\end{document}
여기서 내가 원하는 것은 all 을 유지하면서 정수가 아닌 값을 \addplot[black] table[x=N, y expr=\thisrow{N}/\relativeTo] {\loadedtable};
추가하지 않는 것입니다 .y ticks
\thisrow{N}/\relativeTo
x ticks
(x_min, 1)에서 (x_max, x_max/x_min)까지 선형 함수를 그리는 다른 방법이 있으면 좋은 대응을 가지면서 y ticks
(아마도 다른 테이블을 생성하여?) 그것도 트릭을 수행할 것입니다.
이는 '즉시' 플롯 생성을 위한 것이므로 선험적으로 내 값을 모르므로 이 경우에는 사용할 수 없습니다 y tick={1,...,6}
.
답변1
일부 if 조건을 통해 눈금 레이블에 대한 허용 오차를 도입할 수 있습니다.
\documentclass{standalone}
\usepackage{amsmath,amssymb,siunitx}
\usepackage{pgfplotstable}
\begin{filecontents}{PJxpGrZtwos.tex.dat}
N f M
1024 3.407938e+01 25
1536 1.339487e+01 20
2048 1.139487e+01 19
3072 8.351236e+00 14
4049 6.466788e+00 13
6144 4.466788e+00 11
\end{filecontents}
\pgfkeys{/pgf/fpu=true}
\pgfplotstableread{PJxpGrZtwos.tex.dat}\loadedtable
\pgfplotstablegetelem{0}{N}\of{\loadedtable}
\let\relativeTo\pgfplotsretval
\pgfplotstablegetelem{0}{f}\of{\loadedtable}
\let\f\pgfplotsretval
\pgfplotstablecreatecol[create col/expr={\f / \thisrow{f}}]{f-relative}\loadedtable
\pgfkeys{/pgf/fpu=false}
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}[
axis y line*=left,
legend pos=south east,
xlabel={N},
xtick=data,
xticklabels from table={\loadedtable}{N},
ytick=data,
yticklabel={
\pgfmathparse{abs(exp(\tick) - int(exp(\tick)))}
\ifdim\pgfmathresult pt>0.999 pt
\pgfmathparse{exp(\tick)}
\pgfmathprintnumber{\pgfmathresult}
\else
\ifdim\pgfmathresult pt<0.01 pt
\pgfmathparse{exp(\tick)}
\pgfmathprintnumber{\pgfmathresult}
\else{}
\fi
\fi
},
ylabel ={$\dfrac{f(\pgfmathprintnumber\relativeTo)}{f(N)}$}]
\addplot[black] table[x=N, y expr=\thisrow{N}/\relativeTo] {\loadedtable};
\addplot[blue, mark=*] table[x=N, y=f-relative] {\loadedtable};
\legend{{Linear progression},}
\end{loglogaxis}
\begin{semilogxaxis}[ymin = 5, ytick={10, 15, ..., 30}, ymax = 35, axis x line=none,ylabel={\# M}, axis x line=none, axis y line*=right, ylabel near ticks=right, yticklabel pos=right]
\addplot[red, dotted, mark=x, mark options={solid}] table[x=N, y=M] {\loadedtable};
\end{semilogxaxis}
\end{tikzpicture}
\end{document}
답변2
분명한 해결책이 나를 깨웠다. "ytick=data" 부분을 삭제하세요. 제가 뭔가 잘못 이해한 걸까요?
\documentclass[10pt]{article}
\usepackage{tikz}
\usepackage{pgfplotstable}
\usepackage[active, pdftex, tightpage]{preview}
\PreviewEnvironment[{[]}]{tikzpicture}
\setlength\PreviewBorder{2mm}
\begin{filecontents}{Dkb0rjC9L.tex.dat}
x y
1 1
2 1.5
3 2
4 3
5 4
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xtick=data]
\addplot table {Dkb0rjC9L.tex.dat};
\end{axis}
\end{tikzpicture}
\end{document}