2

The problem was already resolved 6 years ago in a very nice way. However is there any way to split that table into few parts and change colors of bar plots - like on the pic? Below there is a code from that response.

\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{pgfplotstable}
\usepackage{filecontents}

% The data file % In a real application, this would be a text file in your file system \begin{filecontents}{data.txt} function,cpu time Loop at line 151,3.42 Loop at line 107,3.27 Scalar face value,3.09 Loop at line 102,1.7 Get sensible enthalpy,1.25 Compare vec3,1.14 \end{filecontents}

\pgfplotstableread[col sep=comma]{data.txt}\data

% Define the command for the plot \newcommand{\errplot}{% \begin{tikzpicture}[trim axis right] \begin{axis}[y=-\baselineskip, scale only axis, width=5cm, enlarge y limits={abs=0.5}, axis y line=middle, ytick=\empty, axis x line=bottom, xbar, bar width=1.5ex, xmin=0, visualization depends on=x \as \rawx, nodes near coords, every node near coord/.style={ anchor=east, shift={(axis direction cs:-\rawx,0)} } ] %

\addplot [draw=black, fill=red] table [x=cpu time,y expr=\coordindex]{\data}; \end{axis} \end{tikzpicture}% }

\begin{document}

% Get number of rows in datafile \pgfplotstablegetrowsof{\data} \let\numberofrows=\pgfplotsretval

% Print the table \pgfplotstabletypeset[columns={function, cpu time}, % Booktabs rules every head row/.style={before row=\toprule,after row=\midrule}, every last row/.style={after row=[3ex]\bottomrule}, % Set header name columns/function/.style={string type,column type=l,column name=Function}, columns/cpu time/.style={ column name={CPU Time}, assign cell content/.code={% use \multirow for Z column: \ifnum\pgfplotstablerow=0 \pgfkeyssetvalue{/pgfplots/table/@cell content} {\multirow{\numberofrows}{6.5cm}{\errplot}}% \else \pgfkeyssetvalue{/pgfplots/table/@cell content}{}% \fi } }, ]{\data} %Done! \end{document}

enter image description here

0 Answers0