2

I have multiple .csv files which are organized like force-stats.txt (see MWE below). I'd like to make a plot based on several single points in these data files. Is this possible? So far searches with mutations of terms like "single / same / data / points / coordinates" did not lead too something useful.

The MWE below displays data as it should for the entire column in a data file, except I mixed it with the labels and ticks how I imagine them to be used.

Picture (bad drawing) of what I would like to achieve

And then there is a rough sketch. I hope the following picture explains how I imagine the data aligned by their own ticks. Note: for the sake of brevity I omitted all the axis labels for y, in case it isn't obvious. :)

enter image description here

MWE

\documentclass[
a4paper
]{scrartcl}

\usepackage{
lmodern,
amsmath,
tikz,
pgfplots,
pgfplotstable
}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}


\begin{filecontents}{force-stats.txt}
Stats,Min,MinStdDev,MinCIP95,Max,MaxStdDev,MaxCIP95
Fx,-7.35,2,0.36,6,1,0.4
Fy,-4,0.95,0.76,5,1.91,0.5
Fz,-2,1.42,0.5,4,4,0.5
\end{filecontents}

\begin{filecontents}{force-stats-fake-new.txt}
Stats,Min,MinStdDev,MinCIP95,Max,MaxStdDev,MaxCIP95
Fx,-8.35,2,0.36,7,1,0.4
Fy,-4,0.95,0.76,5,1.91,0.5
Fz,-2,1.42,0.5,4,4,0.5
\end{filecontents}

\pgfplotstableread[col sep=comma]{force-stats.txt}{\tableabcdef}
\pgfplotstableread[col sep=comma]{force-stats-fake-new.txt}{\tableqwertyz}

\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xlabel={Maximum Fx for A and B},
ylabel={Value stuff},
%
ybar,
%
ymin=0,
%
enlarge x limits={0.3},
%enlarge y limits={0.3},
%
symbolic x coords={Fx,Fy,Fz},
%
xtick=data,
nodes near coords,
xticklabels={{A unit},{B unit}}
]
\addplot+[nodes near coords align={above}] table [col sep=comma, x=Stats, y=Max] {\tableabcdef};
\addlegendentry{\( Fxmax^{\text{A}} \)}
\addplot+[nodes near coords align={above}] table [col sep=comma, x=Stats, y=Max] {\tableqwertyz};
\addlegendentry{\( Fxmax^{\text{B}} \)}
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
  • To be honest, I'm not entirely surprised the keywords search gave no relevant result, seeing how hard it is to explain in plain english. I'm still not sure of understanding... Maybe, for better clarity, you should add a mockup of what you want (even if it has to be hand-drawn). – T. Verron Jul 18 '14 at 12:08
  • 2
    /pgfplots/table/create col/copy column from table would enable you to build up a new table from data from different files. – Andrew Swann Jul 18 '14 at 12:12
  • @T.Verron I updated the op with a picture. – henry Jul 18 '14 at 12:39
1

Here is a suggestion using

x filter/.code={\ifnum\coordindex>0\def\pgfmathresult{}\fi}% use only the first coord

to filter the first coordinate in every table and

x expr=\coordindex

for the first plot,

x expr=\coordindex+1

for the second plot. For a third plot ...+2 must be used and so on. Note that \coordindex starts with 0.

enter image description here

Code:

\documentclass[margin=10pt]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.10}

%\begin{filecontents}{force-stats.txt}
%Stats,Min,MinStdDev,MinCIP95,Max,MaxStdDev,MaxCIP95
%Fx,-7.35,2,0.36,6,1,0.4
%Fy,-4,0.95,0.76,5,1.91,0.5
%Fz,-2,1.42,0.5,4,4,0.5
%\end{filecontents}
%\begin{filecontents}{force-stats-fake-new.txt}
%Stats,Min,MinStdDev,MinCIP95,Max,MaxStdDev,MaxCIP95
%Fx,-8.35,2,0.36,7,1,0.4
%Fy,-4,0.95,0.76,5,1.91,0.5
%Fz,-2,1.42,0.5,4,4,0.5
%\end{filecontents}
\pgfplotstableread[col sep=comma]{force-stats.txt}{\tableabcdef}
\pgfplotstableread[col sep=comma]{force-stats-fake-new.txt}{\tableqwertyz}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xlabel={Maximum $Fx$ for A and B},
    ylabel={Value stuff},
    legend pos=outer north east,
    ybar=-10pt,% -10pt if bar width=10pt
    ymin=0,
    enlarge x limits={0.3},
    xtick={0,1},
    nodes near coords,
    xticklabels={{A unit},{B unit}},
    x filter/.code={\ifnum\coordindex>0\def\pgfmathresult{}\fi}% use only the first coord
  ]
  \addplot table [ x expr=\coordindex, y=Max] {\tableabcdef};
  \addlegendentry{\( Fxmax^{\text{A}} \)}
  \addplot table [x expr=\coordindex+1, y=Max] {\tableqwertyz};
  \addlegendentry{\( Fxmax^{\text{B}} \)}
  \end{axis}
\end{tikzpicture}
\end{document}

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.