6

I'm trying to use a macro for pgfplotstable labels but the macro is treated as a single entry of a csl rather than a csl.

The Question asked in Using a macro as value of addtotoc in \includepdf answered my question but I'm not able to do the same.

test.csv:

category, value, value 2
cat a,  1,  7
cat b,  2,  6
cat c,  3,  5
cat d,  4,  4
cat e,  5,  3
cat f,  6,  2
cat g,  7,  1

The code:

\def\blah{a,b,c,d,e,f,g}

\def\plotTable{
  \begin{tikzpicture}
    \begin{axis}[ybar,
                 ymin=0,
                 xlabel=X Label,
                 ylabel=Y Label,
                 xticklabel style={text height=1.5ex},
                 xtick=data,
                 xticklabels={\blah},
                 nodes near coords,
                 nodes near coords align={vertical},
                 width=80mm,
                 height=80mm,
                 area legend,
                 legend pos=outer north east,
                 legend entries={a,b},
                 bar width=3mm]
      \addplot table [x expr=\coordindex, y=value, col sep=comma] {test.csv};
      \addplot table [x expr=\coordindex, y=value 2, col sep=comma] {test.csv};
    \end{axis}
  \end{tikzpicture}
}

Manually typing out

xticklabels={a,b,c,d,e,f,g},

shows the labels for each column (rather than clustered to label the first column)

Is there an easy way to be able to put a macro there?

Thanks

  • Use xticklabels/.expand once=\blah instead of just xticklabels=\blah – Jake Jan 7 '14 at 21:24
  • @Jake You my friend, are awesome! – dsm5 Jan 7 '14 at 22:09
3

@Jake had the answer in the comment:

Use xticklabels/.expand once=\blah instead of xticklabels=\blah

Thanks!

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.