绘制带有填充区域和日期图的垂直线

绘制带有填充区域和日期图的垂直线

我想在图形中添加带有一些文字的垂直线,但我还没有找到方法。

我尝试过类似

\addplot coordinates { (2008-01-01,0)  (2008-01-01,130)} node {some text};

但它不起作用,我被困住了

这是一个最小的工作示例,它首先创建 ybar 堆叠

\documentclass{standalone}              
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}

\begin{document}

\pgfplotstableread[col sep=comma,header=true]{
Year,1,1.1,1.2,1.3,1.4
2005,0,0.29,21.97,42.22,27.98
2006,0,1.43,8.25,47.53,29.96
2007,0.05,0.05,13.62,45.26,34.05
2008,0.06,0.89,10.63,30.84,44.63
2009,0.09,0,7.71,30.82,46.75
2010,0,0,1.65,28.34,27.02
2011,0,0,0.94,29.02,7.64
}\data

\begin{tikzpicture}     
    \begin{axis}[
            stack plots=y,
            area style,                  
            enlarge x limits=false,
            enlarge y limits=upper,                     
            x tick label style={/pgf/number format/1000 sep=},      
    ymax=150
        ]
        \addplot table [x=Year, y=1] {\data} \closedcycle;
        \addplot table [x=Year, y=1.1] {\data} \closedcycle;             
        \addplot table [x=Year, y=1.2] {\data} \closedcycle;
        \addplot table [x=Year, y=1.3] {\data} \closedcycle;
        \addplot table [x=Year, y=1.4] {\data} \closedcycle;     
        \end{axis}
\end{tikzpicture}


\end{document}

答案1

您可以使用 输入轴的坐标系 (cs) axis cs。每当您想要向图中添加某些内容时,都应该使用它,因为pgfplots它会处理适当的数据缩放、对数甚至symbolic x coords。请看下面的内容,这可能会给您一个很好的起点。

\documentclass{standalone}              
\usepackage{pgfplots}
%\usepgfplotslibrary{dateplot}

\begin{document}

\pgfplotstableread[col sep=comma,header=true]{
Year,1,1.1,1.2,1.3,1.4
2005,0,0.29,21.97,42.22,27.98
2006,0,1.43,8.25,47.53,29.96
2007,0.05,0.05,13.62,45.26,34.05
2008,0.06,0.89,10.63,30.84,44.63
2009,0.09,0,7.71,30.82,46.75
2010,0,0,1.65,28.34,27.02
2011,0,0,0.94,29.02,7.64
}\data

\begin{tikzpicture}     
    \begin{axis}[
            stack plots=y,
            area style,                  
            enlarge x limits=false,
            enlarge y limits=upper,                     
            x tick label style={/pgf/number format/1000 sep=},      
    ymax=150
        ]
        \addplot table [x=Year, y=1] {\data} \closedcycle;
        \addplot table [x=Year, y=1.1] {\data} \closedcycle;             
        \addplot table [x=Year, y=1.2] {\data} \closedcycle;
        \addplot table [x=Year, y=1.3] {\data} \closedcycle;
        \addplot table [x=Year, y=1.4] {\data} \closedcycle;  
        \draw (axis cs:2006,0) -- (axis cs:2006,130) node [above] {Some text};
        \node [coordinate, pin=above:{Some other text}] at (axis cs:2008,130) {};
        \draw (axis cs:2010,0) |- (axis cs:2009,110) node [left] {Some more text};
        \end{axis}
\end{tikzpicture}
\end{document}

您可以在以下文档中找到更多信息pgf图

结果:

结果

相关内容