I want to plot a simple function on a plot where date coordinates are used in x but it seems that pgfplots cannot accept both. Here's a MWE of what I'm trying to achieve:
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[date coordinates in=x,date ZERO=2013-08-18,
xticklabel=\month-\day,ymin=0,ymax=10000]
\addplot coordinates {
(2013-08-18, 14)
(2013-08-25, 245)
(2013-08-31, 3412)
(2013-09-04, 4567)
(2013-09-05, 5001)
(2013-09-12, 6891)
(2013-09-13, 7456)
(2013-09-15, 8234)
(2013-09-21, 9456)
};
\addplot [red] expression {1/(1+exp(-x))}; % <-- fails if uncommented
\end{axis}
\end{tikzpicture}
\end{document}
From what I understand, pgfplots cannot accept a domain when date coordinates are used because they are not really numbers. So domain=2013-08-18:2013-09-21
won't work, not even when each date is surrounded by braces. samples at
was not effective either.
I wonder if it is possible to use a dynamically set domain–the Unix epoch of date ZERO
, via Lua perhaps? Or is not possible at all to combine dates and have a domain for a function?
Best Answer
If you want to set the minimum and maximum values for the x-axis, you can use
xmin
andxmax
, like so:I don't believe that you can do computations with the x values in the plot because they are dates, not floats. This explains why your second
\addplot
fails.If you want to plot a function of the number of days since 2013/08/18, say 13 * exp(x), you could use Excel for example to compute the function value and save it as a csv file:
In my case, I saved it as a file
2014-01-19.csv
. Then you could plot the graph by reading the function values as a table from the file.