3

i have a problem with pgfplotstable. ( for my box plot , i need one dimension table ), so i use \pgfplotstablevertcat and

\pgfplotstablenew[
  create on use/new/.style={create col/expr={\j }}, columns={new}] {\pgfplotsretval }   \tableinter

but if \pgfplotsretval=1 or \pgfplotsretval=0, the new table have 2 rows !

i try :

 \pgfplotstablenew[
  create on use/new/.style={create col/expr={\j }}, columns={new}] {\pgfplotsretval }   \tableinter

or

\pgfplotstablenew[
  create on use/new/.style={create col/expr={\j }}, columns={new}] {0}   \tableinter

it's the same : two row...

\documentclass{article}
\usepackage{multicol}
\usepackage{pgfplotstable}

\begin{document}
My pgfplots version is: \pgfplotsversion
 \pgfplotstableset{every head row/.style={output empty row}}

\pgfplotstableread{
     1      3   
     2      1
     3      6
     4      10
     5      6
     6      2
     7      1
     8      0
     }\datatable

 \begin{multicols}{2}    
     \pgfplotstabletypeset{\datatable}    


          \pgfplotsforeachungrouped \i in {0,...,7}{ 

        \pgfmathtruncatemacro{\j}{mod(\i+1,10)} 
       \pgfplotstablegetelem{\i}{[index]1}\of\datatable   



%     \ifnum\pgfplotsretval =0 \relax

   %                         \else



        \pgfplotstablenew[
  create on use/new/.style={create col/expr={\j }}, columns={new}] {\pgfplotsretval }   \tableinter
%                        \fi

%                             \pgfplotstablevertcat{\names}{\essai}                   
      \pgfplotstablevertcat{\table}{\tableinter}           

      }  
      \par 
          \pgfplotstabletypeset{\table}   

\end{multicols}

\end{document}

can someone explain this ? enter image description here

1

It seems that it is not possible to create a table with less than two rows (except the header):

\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}% <- to avoid the pgfplots warning
\begin{document}
\pgfplotstablenew[
    create on use/new/.style={create col/expr={\pgfplotstablerow+1}},
    columns={new}
  ]
  {0}% try with other numbers
  \tableinter
The table has {\pgfplotstablegetrowsof{\tableinter}\pgfplotsretval} rows:
\pgfplotstabletypeset\tableinter
\end{document}

Maybe this is a bug.

While its easy to avoid your problem with \pgfplotsretval=0, I can only suggest a workaround for \pgfplotsretval=1: Replace the entry in the second by NaN. AFAIK cells with a NaN entry will be ignored by \addplot.

\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}% <- to avoid the pgfplots warning
\begin{document}
My pgfplots version is: \pgfplotsversion.

\pgfplotstableset{
  every head row/.style={output empty row},
  begin table/.add={}{[t]}%
}
\begin{center}
\pgfplotstableread{
     1      3   
     2      1
     3      6
     4      10
     5      6
     6      2
     7      1
     8      0
     }\datatable
  \pgfplotstabletypeset{\datatable}
  \qquad
  \pgfplotsforeachungrouped \i in {0,...,7}{%
    \pgfmathtruncatemacro{\j}{mod(\i+1,10)}%
    \pgfplotstablegetelem{\i}{[index]1}\of\datatable
    \ifnum\pgfplotsretval =0
    \else
      \pgfplotstablenew[
          create on use/new/.style={create col/expr={\j}},
          columns={new}
        ]{\pgfplotsretval}\tableinter
      % if there should be only one row, replace the contents of the second by "nan"
      \ifnum\pgfplotsretval=1
        \pgfplotstablemodifyeachcolumnelement{new}\of\tableinter\as\cellcontent{\pgfmathsetmacro{\cellcontent}{(\pgfplotstablerow==1?NaN:\cellcontent)}}%
      \fi
      \pgfplotstablevertcat{\table}{\tableinter}%
    \fi
  }
  \pgfplotstabletypeset{\table}
\end{center}
\end{document}

results in

enter image description here

  • Cool, i'll try to have my box plot with this and see if Nan is not a problem for this. – macapus Jun 4 '17 at 16:29
0

seems to be ok !:

\documentclass[a4paper]{article}
\usepackage{pgf,tikz}

% % % % % % % % % stats
\usepackage{pgfplots} % Use tikzpicture for the diagrams
\pgfplotsset{compat=newest}

%\usepgfplotslibrary{statistics}% pgf-Libraries besser so laden
\usepackage{pgfplotstable}
 \usetikzlibrary{pgfplots.statistics}
\usepackage{array}
% % % % % % % % set comma for french decimal separator
\pgfset{/pgf/number format/dec sep={,}}
 \pgfkeys{/pgf/number format/.cd, set decimal separator={,},set thousands separator={\ }}   


 \begin{document}

My pgfplots version is: \pgfplotsversion.

\pgfplotstableset{
  every head row/.style={output empty row},
  begin table/.add={}{[t]}%
}
\begin{center}
\pgfplotstableread{
     x      effectif
     1      3   
     2      1
     3      5
     4     8
     5      5
     6      2
     7      2
     8      1
     }\datatable
  \pgfplotstabletypeset{\datatable}
  \qquad

    \pgfplotsforeachungrouped \i in {0,...,7}{%
       \pgfmathtruncatemacro{\j}{mod(\i+1,10)}%
       \pgfplotstablegetelem{\i}{[index]1}\of\datatable
       \ifnum\pgfplotsretval =0
       \else
         \pgfplotstablenew[
             create on use/new/.style={create col/expr={\j}},
             columns={new}
           ]{\pgfplotsretval}\tableinter
         % if there should be only one row, replace the contents of the second by "nan"
         \ifnum\pgfplotsretval=1
           \pgfplotstablemodifyeachcolumnelement{new}\of\tableinter\as\cellcontent{\pgfmathsetmacro{\cellcontent}{(\pgfplotstablerow==1?NaN:\cellcontent)}}%
         \fi
         \pgfplotstablevertcat{\table}{\tableinter}%
       \fi
     }
     \pgfplotstabletypeset{\table}


                                                               \par 


\begin{tikzpicture}
    \begin{axis}
        [boxplot/draw direction=x, y=1.5cm,ymax=2,
        boxplot/average=auto, boxplot/every average/.style={mark=},
      %   [y=1.5cm, ymax=2,
         ytick={1,3,...,9}, xtick={0.5,1.5,2.5,3.5,4.5,5.5,6.5}, xticklabels={0.5, 1.5, 2.5,3.5,4.5,5.5,6.5},
         someline/.style={ultra thick,red}
        ]
      \addplot+[boxplot] table[y=new]\table coordinate (A) at (boxplot box cs: \boxplotvalue{average}, 0.5)
      node at
          (boxplot box cs: \boxplotvalue{lower whisker},1.25)
         {\pgfmathprintnumber{\boxplotvalue{lower whisker}}} 
      node at
        (boxplot box cs: \boxplotvalue{lower quartile},1.25)
        {\pgfmathprintnumber{\boxplotvalue{lower quartile}}} 
         node at
            (boxplot box cs: \boxplotvalue{upper quartile},1.25)
           {\pgfmathprintnumber{\boxplotvalue{upper quartile}}}           
           node at
              (boxplot box cs: \boxplotvalue{upper whisker},1)
              {\pgfmathprintnumber{\boxplotvalue{upper whisker}}}
       node[left] at
           (boxplot box cs: \boxplotvalue{median},0.5)         
           {\pgfmathprintnumber{\boxplotvalue{median}}}  
         ;
\end{axis}
\end{tikzpicture}

\end{center}


\end{document}

enter image description here

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.