1

How could I add a trend line to this plot? Many thanks!

\begin{tikzpicture}
  \begin{axis}[
    date coordinates in=x,
    xtick=data,
    xticklabel style=
        {rotate=90,anchor=near xticklabel},
    xticklabel=\day. \hour:\minute,
    date ZERO=2009-08-18,% <- improves precision!
  ]
  \addplot coordinates {
    (2009-08-18 09:00,  050)
    (2009-08-18 12:00,  100)
    (2009-08-18 15:00,  100)
    (2009-08-18 18:35,  100)
    (2009-08-18 21:30,  040)
    (2009-08-19,        020)
    (2009-08-19 3:00,   000)
    (2009-08-19 6:0,    035)
};
  \end{axis}
\end{tikzpicture}
  • See tex.stackexchange.com/questions/11251/…. Alternatively, you could just calculate the equation of the line and plot it with another \addplot command. – JamesNZ Oct 29 '15 at 2:39
  • pgfplots at present has only linear regression. So you have to find the equation yourself. And then plot that also. – user11232 Oct 29 '15 at 2:49