to this question (pgfplots(table) spreadsheet like formulas) I got the comment that it could be done with the package datatool. But actually I have problems passing the data from datatool to pgfplots.
Things like this:
\documentclass[border=3pt]{standalone}
\usepackage{datatool}
\usepackage{pgfplots}
\catcode`\^^I=12 %
\DTLsetseparator{ }%
\pgfplotsset{compat=1.12}
\DTLloaddb{coordinates}{data.csv}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ytick={5,6,7},
xtick=data
]
\DTLforeach*{coordinates}{\x=x,\y=y}{%
\ifnum\value{DTLrowi}>1
\addplot coordinates {(\mtx,\mty) (\x,\y)};
\fi
\xdef\mtx{\x}\xdef\mty{\y}
}
\end{axis}
\end{tikzpicture}
\end{document}
Do not work properly, since I get always two points for one curve, then a new totally independent curve is drawn. This is logically absolute not what I intend to do. My aim is to rea the data from the file, process it with datatool and plot them then with pgfplots (yes I know there is datatoolplot, but pgfplots is more flexible).
Furthermore a loop with an if to insert the data to pgfplots seems very long winded to me.
Can anyone think of a better more simple way to achieve this (and especially pass all data to one plot, not as many lines as in the files are (minus one))?
EDIT: Data file may look like this (tab separated):
x y
1 2
2 4
3 2
4 0

pgfplots. You do not needdatatoolat all. Please post the question in such a way that others understand why you are doing what you are doing. – Mar 21 '20 at 01:19datatool. I assume that the manipulation part is left out here to make the question more minimal. – Marijn Mar 21 '20 at 14:54\pgfplotstablegetelemone can access every singe element of a table, and with\pgfmathdeclarefunctionone can define functions that do something with table entries. I would be very hesitant to mix two different tools unless there is a clear need for that. So IMHO the OP should really explain what they want to achieve, and why they do what they do. – Mar 21 '20 at 15:01pgfplotsorpgfplots+datatool) are. – Marijn Mar 21 '20 at 15:08\addplotcommands makes less sense. But there is also absolutely no need to do that loop, at least I cannot see a reason why one wants to do that. So we are back at start. ;-) – Mar 21 '20 at 15:14\pgfplotstablegetelemand\pgfmathdeclarefunctionto create a new dataset (aka column) for each row in the table but only to select rows for use in plaintext. – atticus Mar 21 '20 at 15:57datatool, for example combine rows from two csv files by key, which is more difficult to do withpgfplots. – Marijn Mar 21 '20 at 15:59datatool+pgfplotscombination is great and easy, and the pure pgfplots solution sucks. I may not knowdatatoolwell enough, but I do not see that without an explicit case. (BTW,forget plotalso suppresses the legend. Also by patching the plots together like that you lose access to important features like adding asmoothkey, having cool functions of\coordindex, and so on. While I upvoted many of your answers I won't upvote this one for that reason.) – Mar 21 '20 at 16:08\addplotcommand, as in https://tex.stackexchange.com/questions/266332/iterating-through-a-table-using-values-on-the-next-row. – Marijn Mar 22 '20 at 09:45