Commit 02026e31 authored by Alexander Povel's avatar Alexander Povel
Browse files

Add dateplot pgfplots section

parent 079faf45
......@@ -1143,6 +1143,96 @@ lines that effectively do something useful.
Time-series plots are straightforward to implement.
\ctanpackage{pgfplots}, using its \texttt{dateplot} library, can automatically parse
and plot dates.
For this to work best and most reliably, dates and times should be in
\abb{international_organization_for_standardization} 8601 format:
\texttt{YYYY-MM-DDThh:mm:ss\phantom{Z}}:% \phantom for budget alignment
where \texttt{Z} is time\-/zone information and \texttt{T} is an arbitrary, but
fixed separator.
It can also be a simple space.
Use just the date \emph{or} time part when appropriate.
This format is unambiguous and understood worldwide as well as, most importantly here,
by computers.
No extra string and date parsing is required, it will just work in a lot of cases,
not only for \ctanpackage{pgfplots} in this case.
Further, it is often the standard output format of measurement equipment anyway,
so there is not even a need to modify those.
An example is shown in \cref{fig:example_timeseries_plot}.
Note how the actually displayed date/time format can be modified and made human\-/readable
Only the underlying data format is best followed strictly in
\abb{international_organization_for_standardization} 8601 format.
% Data is small enough to not require a separate CSV file, put it here.
% Specify date as YYYY-MM-DD for pgfplots to recognize it as date data automatically.
% Currently, the xlabel alignment is off using dateplots, so revert to plain
% old methods for now.
\pgfplotstableread[row sep=\\]{%
Year, Value1, Value2, Value3, Value4, Value5, Value6, Value7\\%
2020-02-01, 50, 1, 5, 10, 15, 2, 17\\%
2020-03-04, 40, 2, 4, 10, 10, 2, 32\\%
2020-05-02, 30, 3, 3, 10, 15, 2, 37\\%
2020-05-28, 20, 4, 2, 10, 10, 2, 52\\%
2020-06-14, 10, 5, 1, 10, 15, 2, 57\\%
\caption[Example automatic timeseries plot]{
Example automatic timeseries plot.
Note the automatic spacing\-/out according to the actual time deltas,
and the automatic conversion of timestamps to human\-/friendly versions,
to whatever specification the author chooses%
ybar stacked,
xtick=data,% xticks at data points, not uniformly
% Use next line for manual labels from table; get from {<table>}{<column>}
% xticklabels from table={\examplepfgtable}{year},
% If using date data in the table (of the form YYYY-MM-DD):
date coordinates in=x,
% Customize display here; macros automatically defined/grabbed
% by pgfplots:
xticklabel style={rotate=45,anchor=north east},
ymin=0,% Cuts off data otherwise
y unit={\percent},
legend style={font=\scriptsize},%
% nodes near coords,% uncomment for numeric labels
cycle list/Set2-7,
every axis plot/.append style={fill},%
\foreach \i in {1, ..., 7}{%
\addplot+ table [y=Value\i] {\examplepfgtable};
\legend{Value1, Value2, Value3, Value4, Value5, Value6, Value7}
\subsubsection{Importing CSV}
Often, one wants to plot data from files.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment