PGFPLOTS 正しい位置に追加の xtick または垂直線を追加するにはどうすればよいでしょうか?

PGFPLOTS 正しい位置に追加の xtick または垂直線を追加するにはどうすればよいでしょうか?

これが実際の厚さの構成であることを示すために、座標 x= 3.5 に垂直線を追加しようとしています。ただし、以下の試みでは、軸上の正しい位置に目盛りが配置されません。理想的には、垂直線に加えて、「実際」などのメモを追加したいと思います。

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{siunitx}
\usepackage{filecontents}

\begin{document}

\begin{filecontents}{data.csv}
{Thickness (mm)};{Trise ambient temp};{T-rise at max.temp};{T-rise ambient (narrow)};{T-rise max temp. (narrow)}
3;30;51;46;79
4;21;37;33;56
5;16;28;25;43
6;13;23;20;34
7;11;19;16;28
\end{filecontents}

\pgfplotstableread[col sep = semicolon]{data.csv}{\datatable}

\begin{tikzpicture}
\begin{axis}[height=.6\textwidth, width=\textwidth,
thick,
smooth,
grid=both,
xtick=data,
xticklabels from table={\datatable}{[index]0},
extra x ticks={3.5}, % does not work, puts a tick between 6 and 7, with label "3"
xlabel={Thickness (\si{\milli\meter})},
ylabel={T-rise (\si{\celsius)}},
]
\addplot [gray,] table [
x expr=\coordindex, x index =0,
y index=1] {\datatable}
[sloped, font=\small]
node[below, pos=0.25] {T-rise at \SI {0}{\celsius}};
\addplot [blue,] table [
x expr=\coordindex, x index =0,
y index=2] {\datatable}
[sloped, font=\small]
node[above, pos=0.25] {T-rise at \SI {180}{\celsius}};
%\draw[ultra thin] (axis cs:3.5,\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs:3.5,\pgfkeysvalueof{/pgfplots/ymax}); draws a vertical line, but at x=4
\end{axis}
\end{tikzpicture}
\end{document}

答え1

座標インデックスを y データに対してプロットするには、 を使用する必要がありますx expr=\coordindex,。ただし、ここでは列 0 (x として) と列 1 および 2 (y として) をプロットしています。したがって、 を使用しないでくださいx expr。使用すると、3.5 の追加の目盛りが、表の x ラベルがある 3.5 に表示されます\coordindex。(これは 6.5 です)。

結論:削除 x expr=\coordindex,

\documentclass[border=5mm]{standalone}
%\usepackage{pgfplots}  %% loaded by pgfplotstable.
\usepackage{pgfplotstable}
\usepackage{siunitx}
\usepackage{filecontents}
\pgfplotsset{compat=1.11}

\begin{document}

\begin{filecontents}{data.csv}
{Thickness (mm)};{Trise ambient temp};{T-rise at max.temp};{T-rise ambient (narrow)};{T-rise max temp. (narrow)}
3;30;51;46;79
4;21;37;33;56
5;16;28;25;43
6;13;23;20;34
7;11;19;16;28
\end{filecontents}

\pgfplotstableread[col sep = semicolon]{data.csv}{\datatable}

\begin{tikzpicture}
\begin{axis}[height=.6\textwidth, width=\textwidth,
thick,
smooth,
grid=both,
xtick=data,
%xticklabels from table={\datatable}{[index]0},
xlabel={Thickness (\si{\milli\meter})},
ylabel={T-rise (\si{\celsius)}},
extra x ticks={3.5},
extra tick style={grid=major,major grid style={red,thick},
tick label style={
rotate=90,anchor=east}},
extra x tick labels={Actual},
xticklabels from table={\datatable}{[index]0},
]
\addplot [gray,] table [
 x index =0,
y index=1] {\datatable}
[sloped, font=\small]
node[below, pos=0.25] {T-rise at \SI {0}{\celsius}};
\addplot [blue,] table [
x index =0,
y index=2] {\datatable}
[sloped, font=\small]
node[above, pos=0.25] {T-rise at \SI {180}{\celsius}};
%\draw[ultra thin] (axis cs:3.5,\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs:3.5,\pgfkeysvalueof{/pgfplots/ymax}); draws a vertical line, but at x=4
\end{axis}
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

関連情報