플롯의 특정 ybar에 주석이나 화살표를 추가하고 싶지만 기호 x 데이터로 인해 어려움을 겪고 있습니다. 변수 데이터를 읽기 위해 \pgfplotsinvokeforeach를 사용했기 때문에 x 값을 명시적으로 정의하지 않았습니다. 예를 들어 \node[coordinate,pin=right:{Tasmania Entry to NEM}] at (axis cs:2004/5,190) {}; 을 사용하여 좌표를 지정하려고 할 때마다; 오류(부동 소수점 값 아님)가 발생하므로 내 의견을 대략 올바른 위치에 배치하는 숫자 값 0을 사용해야 했습니다. 문제는 원하는 막대의 상단에 배치되도록 올바른 노드를 지정하는 방법입니다. 작업 예는 아래와 같습니다. 하지만 2005/6 y 막대의 왼쪽 상단과 왼쪽에 주석을 배치하고 싶습니다.
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\pgfplotsset{
select row/.style={
x filter/.code={\ifnum\coordindex=#1\else\def\pgfmathresult{}\fi}
}
}
\pgfplotstableread[col sep=comma,header=false]{
1999/00,167.1
2000/1,172.5
2001/2,175
2002/3,179.3
2003/4,184.4
2004/5,188
2005/6,201.7
2006/7,208.3
2007/8,210.2
2008/9,210.5
2009/10,209.8
2010/11,207.5
2011/12,203.4
2012/13,198.2
%2013/14(YTD),97
}\datatable
\begin{tikzpicture}[scale=0.8]
\begin{axis}[
%title=Australia's Primary Energy Consumption by sector - 2012,
ybar, bar shift=0pt,
enlarge y limits=0.1,
%xmin=0,
xtick={0,...,13},
xticklabels from table={\datatable}{0},
ymajorgrids = true,
bar width=3mm,
width=12cm, height=9cm,
xlabel={year},
ylabel={TWh},
x tick label style={font=\footnotesize,rotate=45, anchor=east},
nodes near coords align={horizontal},
]
\pgfplotsinvokeforeach{0,...,13}{
\addplot table [x expr=\coordindex, select row=#1] {\datatable};
}
\node[coordinate,pin=right:{Tasmania entry to NEM}] at (axis cs:0,190) {};
\end{axis}
\end{tikzpicture}
\end{document}
답변1
이것이 가능한 해결책 중 하나입니다. 여기에는 막대 라벨이 명확하게 표시되도록 핀이 추가됩니다.
암호
\documentclass[border=10pt]{standalone}%{article}
\usepackage{pgfplotstable}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\pgfplotsset{
select row/.style={
x filter/.code={\ifnum\coordindex=#1\else\def\pgfmathresult{}\fi}
}
}
\pgfplotstableread[col sep=comma,header=false]{
1999/00,167.1
2000/1,172.5
2001/2,175
2002/3,179.3
2003/4,184.4
2004/5,188
2005/6,201.7
2006/7,208.3
2007/8,210.2
2008/9,210.5
2009/10,209.8
2010/11,207.5
2011/12,203.4
2012/13,198.2
%2013/14(YTD),97
}\datatable
\begin{tikzpicture}[scale=0.8]
\begin{axis}[
%title=Australia's Primary Energy Consumption by sector - 2012,
ybar, bar shift=0pt,
enlarge y limits=0.1,
%xmin=0,
xtick={0,...,13},
xticklabels from table={\datatable}{0},
ymajorgrids = true,
bar width=3mm,
width=12cm, height=9cm,
xlabel={year},
ylabel={TWh},
x tick label style={font=\footnotesize,rotate=45, anchor=east},
nodes near coords align={horizontal},
]
\pgfplotsinvokeforeach{0,...,13}{
\addplot table [x expr=\coordindex, select row=#1] {\datatable};
}
\node[pin={[pin distance=1cm,pin edge={<-,>=stealth'},shift={(-1.2cm,0.5cm)}]
Tasmania entry to NEM}] at (axis cs:5,190) {};
\end{axis}
\end{tikzpicture}
\end{document}