
이것이 실제 두께 구성임을 설명하기 위해 좌표 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
x expr=\coordindex,
좌표 인덱스와 일부 y 데이터를 플롯하는 데 사용해야 합니다 . 그러나 여기서는 열 0(x)과 열 1 및 2(y)를 플롯합니다. 그러므로 사용하면 안 됩니다 x expr
. 그렇게 했기 때문에 3.5의 추가 눈금이\coordindex
테이블의 x 레이블이 있는 3.5에 나타납니다. (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}