如何显示图形轴上某些点的坐标?

如何显示图形轴上某些点的坐标?

这是我想要扩展的代码

\begin{tikzpicture}
\begin{axis}[
date coordinates in=x,
xticklabel={\hour:\minute},
xticklabel style =
{rotate=45,anchor=near xticklabel},
xmajorgrids=true,
xmin={2020-04-04 10:00},
xmax={2020-04-04 11:30},
]
\addplot[color=yellow, mark=square] coordinates {
(2020-04-04 10:00, 0)
(2020-04-04 10:30, 25)
(2020-04-04 10:40, 28)
(2020-04-04 11:00, 40)
(2020-04-04 11:15, 42)
(2020-04-04 11:30, 50)
};
\end{axis}
\end{tikzpicture}

我想显示正方形坐标的坐标在轴线上像这样:

在此处输入图片描述

我该怎么做?谢谢!

答案1

我认为,从原则上来说,这段代码可以满足您的要求。但是,要获得令人满意的结果,必须决定如何排列标签。

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=1.17,
indicate coordinates/.style={scatter,
/pgfplots/date coordinates default inverse={x}{\hour:\minute},
scatter/@pre marker code/.append code={%
\coordinate (tmp);
\draw[dashed,gray] (tmp|-current axis.south) 
node[rotate=45,anchor=north east] {\pgfkeysvalueof{/data point/x}}
|- (tmp-|current axis.west) node[left] {\pgfmathparse{\pgfkeysvalueof{/data point/y}}%
\pgfmathprintnumber\pgfmathresult};
}}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[enlargelimits,
width=14cm,
date coordinates in=x,
xticklabel={\hour:\minute},
xticklabel style =
{rotate=45,anchor=near xticklabel},
xmajorgrids=true,
xmin={2020-04-04 10:00},
xmax={2020-04-04 11:30},
]
\addplot[color=yellow, mark=square,indicate coordinates] coordinates {
(2020-04-04 10:00, 0)
(2020-04-04 10:30, 25)
(2020-04-04 10:40, 28)
(2020-04-04 11:00, 40)
(2020-04-04 11:15, 42)
(2020-04-04 11:30, 50)
};
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容