3

the following mwe:

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=1.15}

\usepackage{filecontents}
\begin{filecontents*}{data.csv}
datum,       s,      zt,      st,      u
2017-09-26,  9.2,    144,     80,      62
2017-09-29,  8.8,    141,     76,      64
2017-10-03,  8.4,    137,     77,      67
2017-10-06,  7.8,    136,     82,      53
2017-10-10,  9.1,    135,     80,      60
2017-10-13,  8.1,    139,     75,      61
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
\centering
\begin{axis}[
    date coordinates in=x,
    xticklabel={\month-\day},
    x tick label style={rotate=45,anchor=north east},
    date ZERO=2017-09-26,
    grid=major, grid style=dashed,
    xlabel={Datum (mesec-dan)},
    ylabel={s},
]
\addplot table [x=datum, y=s, col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}

gives:

enter image description here

  • i like that xtick are aligned with marks and if it is possible equidistant distributed regardless that dates are not (they are periodic, contain measurements are taken on each Tuesday and Friday) and that plot line is (consequently) not interrupted.
  • is possible add days names (Tue, Fri) to xtick label on the way that i extend data.cvs with this names?
2
  • I do not get that output from your code, the plot line is without gaps. Dec 19 '17 at 7:58
  • @TorbjørnT. you have right. now i see, that in drawing images the data.cvs table has empty lines after each second table line which i deleted in my question. unintentional i solved part of my problems, however the main is still reaming (that thick are aligned with marks). i correct my question.
    – Zarko
    Dec 19 '17 at 10:26
4

xtick=data works for dateplots as well, so simply adding that to your axis options will give a tick at each data point.

To have the data points equidistant, you can not use the dateplot stuff, but instead set x expr=\coordindex, and then use xtick=data, xticklabels from table to get whatever ticklabels you'd like. Here I used the date column, which you could modify to include the weekday.

output of code

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplotstable}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=1.15}

\usepackage{filecontents}
\begin{filecontents*}{data.csv}
datum,       s,      zt,      st,      u
2017-09-26,  9.2,    144,     80,      62
2017-09-29,  8.8,    141,     76,      64
2017-10-03,  8.4,    137,     77,      67
2017-10-06,  7.8,    136,     82,      53
2017-10-10,  9.1,    135,     80,      60
2017-10-13,  8.1,    139,     75,      61
\end{filecontents*}

% xticklabels from table can't read comma separated file, I think, so read to macro
\pgfplotstableread[col sep=comma]{data.csv}\Data
\begin{document}
\begin{tikzpicture}
\centering
\begin{axis}[
    xtick=data,
    date coordinates in=x,
    xticklabel={\month-\day},
    x tick label style={rotate=45,anchor=north east},
    date ZERO=2017-09-26,
    grid=major, grid style=dashed,
    xlabel={Datum (mesec-dan)},
    ylabel={s},
]
\addplot table [x=datum, y=s, col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\centering
\begin{axis}[
    xtick=data,
    xticklabels from table={\Data}{datum},
    x tick label style={rotate=45,anchor=north east},
    grid=major, grid style=dashed,
    xlabel={Datum (mesec-dan)},
    ylabel={s},
]
\addplot table [x expr=\coordindex, y=s] {\Data};
\end{axis}
\end{tikzpicture}
\end{document}
1
  • thank you very much for both solutions! they works fine and i already used it my work :-) . now i see that i need to read pgfplots as well pgfplotstable manuals again ...
    – Zarko
    Dec 19 '17 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.