I'm trying to create multiple plots from one pgfplotstable (\data below). I can create the plots by manually editing the data (\dataA and \dataB below) but this is error-prone. Essentially, I need help:
- partitioning the table based on column
cat - duplicating the last row (except
xminisxmaxfrom the previous row) - creating a loop to create multiple
tikzpictures [this I can probably figure out myself!]
\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.15}
\begin{document}
\pgfplotstableread{
x xmin xmax par1 y cat par2
0.5 0 1 yes 0.3 1 no
1.5 1 2 yes 0.6 1 no
2.5 2 3 yes 0.7 1 no
0.5 0 1 yes 0.4 2 no
1.5 1 2 yes 0.5 2 no
2.5 2 3 yes 0.9 2 no
}\data
\pgfplotstableread{
x xmin xmax par1 y cat par2
0.5 0 1 yes 0.3 1 no
1.5 1 2 yes 0.6 1 no
2.5 2 3 yes 0.7 1 no
2.5 3 3 yes 0.7 1 no
}\dataA
\pgfplotstableread{
x xmin xmax par1 y cat par2
0.5 0 1 yes 0.4 2 no
1.5 1 2 yes 0.5 2 no
2.5 2 3 yes 0.9 2 no
2.5 3 3 yes 0.9 2 no
}\dataB
\begin{tikzpicture}
\begin{axis}[ybar, ymin=0, ymax=1, xmin=-0.5, xmax=3.5]
\addplot[black, ybar interval] table[x=xmin,y=y] {\dataA}\closedcycle;
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[ybar, ymin=0, ymax=1, xmin=-0.5, xmax=3.5]
\addplot[black, ybar interval] table[x=xmin,y=y] {\dataB}\closedcycle;
\end{axis}
\end{tikzpicture}
\end{document}
Regarding partitioning the data, I have been able to print the partitioned table, but then how can I use it as input for \addplot?
\newcommand{\filtertable}[2]{
\pgfplotstabletypeset[
columns/par1/.style={string type},
columns/par2/.style={string type},
row predicate/.code={%
\pgfplotstablegetelem{##1}{cat}\of{#1}
\ifnum\pgfplotsretval=#2\relax
\else\pgfplotstableuserowfalse\fi}
]{#1}
}
\filtertable{\data}{1}
\filtertable{\data}{2}
Regarding duplicating the last row, the only relevant value in the last rows is xmin. According to the PGF manual with ybar interval "The last y value will be ignored." I have unsuccessfully tried to create the same plot without the additional row. Note the distance between xmin and xmax must not always equal 1.


Unknown function thisrow_unavailable_load_table_directly. Apparently,\thisrowneeds to be followed with the actual data table and not the variable\data. – u17 Apr 30 '19 at 09:20