增加 \node 选项的长度并改变其颜色

增加 \node 选项的长度并改变其颜色

我想增加节点的垂直长度,以便它也可以延伸到我的图像之外。此外,我需要为每条线选择不同的颜色。

\documentclass{article}
\usepackage{graphicx} % more modern
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{figure}
\vspace{0.5cm}
\centering
\begin {tikzpicture}
\begin {axis}[
title=LastFM,
width=\textwidth,
height=5cm,
grid=both,
unbounded coords=discard,
ylabel=Distance,
xlabel=Days,
]
\addplot+[color=black,sharp plot, mark=none] coordinates{(1,123.247718031613)    (2,111.79445424528)(3,117.439346047226)(4,111.588529876507)(5,110.715852523476)(6,107.172757732551)(7,114.908659377786)(8,129.313572373514)(9,133.656275572829)(10,138.246157270284)(11,125.865007051205)(12,128.171759760097)(13,108.148046676766)(14,119.063008529098)(15,120.166551086398)(16,108.554133960895)(17,128.241958812239)(18,125.650308395961)(19,122.237473795886)(20,110)(21,107.990740343791)(22,113.877126763894)(23,125.283678106927)(24,130.107647738325)(25,131.818056426273)(26,134.476763792114)(27,101.133575038164)(28,119.674558699834)(29,116.952982005591)(30,117.413798166996)(31,110.571244001323)(32,104.019228991567)(33,95.9374796416917)(34,103.923048454133)};
\node[coordinate,pin=above:{10}] at (axis cs:16,128.241958812239) {};
\node[coordinate,pin=above:{10}] at (axis cs:37,117.524465538032) {};
\end{axis}
\end{tikzpicture}
\label{fig}
\caption{My Results}
\end{figure}
\end{document}

结果:

结果

答案1

解答未解答的问题...

axis cs您可以使用不同的坐标系统,例如axis coordinate cs:等。请查看手册以了解更多系统。这里有一个略微过头的解决方案来演示不同的选项。为了能够扩展绘图区域,必须通过 关闭此解决方案的轴的剪切操作clip=false

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{figure}
\centering
\begin {tikzpicture}
\begin {axis}[
title=LastFM,
width=\textwidth,
height=5cm,
grid=both,
unbounded coords=discard,
ylabel=Distance,
xlabel=Days,
clip=false
]
\addplot+[color=black,sharp plot, mark=none] coordinates{(1,123.247718031613)    (2,111.79445424528)(3,117.439346047226)(4,111.588529876507)(5,110.715852523476)(6,107.172757732551)(7,114.908659377786)(8,129.313572373514)(9,133.656275572829)(10,138.246157270284)(11,125.865007051205)(12,128.171759760097)(13,108.148046676766)(14,119.063008529098)(15,120.166551086398)(16,108.554133960895)(17,128.241958812239)(18,125.650308395961)(19,122.237473795886)(20,110)(21,107.990740343791)(22,113.877126763894)(23,125.283678106927)(24,130.107647738325)(25,131.818056426273)(26,134.476763792114)(27,101.133575038164)(28,119.674558699834)(29,116.952982005591)(30,117.413798166996)(31,110.571244001323)(32,104.019228991567)(33,95.9374796416917)(34,103.923048454133)};
\draw[red,shorten <=-5mm] ({axis cs:16,120} |- {axis description cs:0,0}) -- ([yshift=5mm]{{axis cs:16,120} |- {axis description cs:0,1}}) node[above] {$10$};
\draw[green,shorten <=-5mm] ({axis cs:37,120} |- {axis description cs:0,0}) -- ([yshift=5mm]{{axis cs:37,120} |- {axis description cs:0,1}}) node[above] {$10$};
\end{axis}
\end{tikzpicture}
\label{fig}
\caption{My Results}
\end{figure}
\end{document}

在此处输入图片描述

相关内容