我知道如何使用以下代码显示每个数据点附近的 y 坐标
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[title={$E_0 $}, ymax=2.5, yticklabels=,
nodes near coords={\pgfmathprintnumber[precision=4]\pgfplotspointmeta},
nodes near coords align={
shift={(0,1.5cm)},
rotate=90,
pin={[pin distance = 0.75cm,
pin edge={thick,double=yellow}]180:},
text=red
}
]
\addplot [blue!90!white, fill=blue!50!white, ybar] coordinates {
( 1, 1.96556 )
( 2, 1.86105 )
( 3, 1.93185 )
( 4, 2.02568 )
( 5, 2.12077 )
( 6, 2.21219 )
};
\end{axis}
\end{tikzpicture}
\end{document}
实际上,我目前正在使用以下代码来显示所选数据点的 y 坐标。
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\pgfplotsset{
pin near coord/.style args={#1/#2/#3}{% Style for activating the label for a single coordinate
scatter/@pre marker code/.append code={
\ifnum 1=#3
\ifnum\coordindex=#1 \node[pin={#2:\small\pgfmathprintnumber{\pgfplotspointmeta} }]{};\fi
\fi
\ifnum 2=#3
\ifnum\coordindex=#1 \node[pin=#2]{};\fi
\fi
}
},
pins near some coords/.style={ % Style for activating the label for a list of coordinates
scatter,
scatter/@pre marker code/.code={},% Reset the default scatter style, so we don't get coloured markers
scatter/@post marker code/.code={},%
pin near coord/.list={#1} % Run "pin near coord" once for every element in the list
}
}
\begin{tikzpicture}
\begin{axis}[width=0.9\textwidth]
\addplot [only marks, mark=*] table[each nth point={2}, x=I, y=V, col sep=comma] {vp2.csv};
\addplot [only marks, mark=*, pins near some coords={0/south/1, 1/south/1, 2/south/1, 3/south/1, 4/south/1} ] table[x=I, y=V, col sep=comma] {minima2.csv};
\end{axis}
\end{tikzpicture}
\end{document}
如何显示 x 坐标?
答案1
像这样吗?
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[title={$E_0 $}, ymax=2.5, yticklabels=,
nodes near coords={\pgfmathprintnumber[precision=4]\pgfplotspointmeta},
nodes near coords align={anchor=west,yshift=0.75cm,
rotate=90,
pin={[pin distance = 0.75cm,
pin edge={thick,double=yellow}]180:},
text=red
}
]
\addplot [blue!90!white, fill=blue!50!white, ybar] coordinates {
( 1, 1.96556 )
( 2, 1.86105 )
( 3, 1.93185 )
( 4, 2.02568 )
( 5, 2.12077 )
( 6, 2.21219 )
};
\end{axis}
\end{tikzpicture}
\end{document}