Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I need to use the math symbol \times on the x axis because the x axis represents image dimensions. But latex doesnt allow me to proceed with this. It gives me hundreds

missing \endgroup inserted

error messages.

Could someone please help me

\begin{figure}[H]
  \begin{adjustwidth}{-.1in}{+.0in} 
\begin{tikzpicture}
\begin{axis}[
scaled y ticks=real:150,
ytick scale label code/.code={},
ymax = 150, ymin = 0,
symbolic x coords={8 \times 8, 16 \times 16,32 \times 32,64 \times 64},
xtick=data,
height=11cm,
width=8cm,
grid=major,
xlabel={Bitmap Dimensions},
ylabel={Accuracy},
legend style={
cells={anchor=east},
legend pos=south east,
},
cycle list name=black white
]

\addplot coordinates {
 (8 \times 8, 22)  (16 \times 16, 23)  (32 \times 32, 23)  (64 \times 64, 122) };

 \addplot coordinates {
 (8 \times 8, 56)  (16 \times 16, 55)  (32 \times 32, 99)  (64 \times 64, 140) };

 \addplot coordinates {
 (8 \times 8, 22)  (16 \times 16, 75)  (32 \times 32, 89)  (64 \times 64, 130) };

 \addplot coordinates {
 (8 \times 8, 108)  (16 \times 16, 145)  (32 \times 32, 144)  (64 \times 64, 149) };

 \addplot coordinates {
 (8 \times 8, 109)  (16 \times 16, 111)  (32 \times 32, 145)  (64 \times 64, 145) };

 \addplot coordinates {
 (8 \times 8, 56)  (16 \times 16, 111)  (32 \times 32, 150)  (64 \times 64, 146) };

 \addplot coordinates {
 (8 \times 8, 77)  (16 \times 16, 111)  (32 \times 32,  133)  (64 \times 64, 147) };
\legend{$A$,$B$,$C$,$D$,$E$,$F$,$G$} 
\end{axis} 
\end{tikzpicture} 
\caption{
Accuracy variation with increasing bitmap dimensions} 
\label{fig:accresplot} 
   \end{adjustwidth}
\end{figure}
share|improve this question
    
Please post a MWE, so we don't have to guess which packages you are loading. It's not clear to me what you really want to do: What do you mean by a coordinate (8x8,77)? Since all the data in the example are "square", I'm guessing you want coordinates (8,77) instead and then somehow show that the numbers on the x-axis represent image dimensions. –  mrf Aug 8 '12 at 9:19
    
Are you using the scaled y ticks=real:150 code to divide your y coordinates by 150? In that case, I would recommend using y filter/.code={\pgfmathparse{#1/150}}, which transforms the data, not just the tick labels, which will lead to better tick label values. –  Jake Aug 8 '12 at 9:44
add comment

2 Answers

up vote 7 down vote accepted

I wouldn't use symbolic coordinates for this, as it makes the data input incredibly tedious. Instead, I would recommend just setting the tick labels to the desired format, and using "proper" coordinates for the data.

Instead of providing the data inline in each \addplot command, I would use a table. Also, you can simplify your code by using \pgfplotsinvokeforeach to loop over the data series.

\documentclass{article}
\usepackage{pgfplots,pgfplotstable}

\pgfplotstableread{
8   22  56  108 109 56  77
16  23  44  145 111 111 111
32  23  99  144 145 150 133
64  122 140 149 145 146 147
}\datatable

\begin{document}

\begin{tikzpicture}
\begin{axis}[
ymin = 0, ymax=1,
y filter/.code={\pgfmathparse{#1/150}},
xtick=data,
height=11cm,
width=8cm,
grid=major,
xlabel={Bitmap Dimensions},
ylabel={Accuracy},
legend style={
    cells={anchor=east},
    legend pos=south east,
},
cycle list name=black white,
xticklabels={$8 \times 8$,
    $16 \times 16$,
    $32 \times 32$,
    $64 \times 64$
}
]

\pgfplotsinvokeforeach {1,...,6}{
    \addplot table [x expr=\coordindex, y index=#1] {\datatable};
}
\legend{$A$,$B$,$C$,$D$,$E$,$F$,$G$} 
\end{axis} 
\end{tikzpicture} 


\end{document}
share|improve this answer
add comment

\times breaks inside \csname that pgfplots needs to build an inverse lookup table.

Many TeX compilers (pdfTeX, LuaTeX, XeTeX) provide \ifincsname that can be used to redefine \times that it survives a \csname.

\let\OrgTimes\times
\protected\def\times{%
  \ifincsname
    \string\times%
  \else
    \OrgTimes
  \fi
}

Then the symbolic coordinates can be given as

$8 \times 8$, $16 \times 16$, ...

(Math mode is needed because of \times and the spacing around \times.)

Inside pgfplots.code.tex it could be fixed by redefining /pgfplots/symbolic coords/.code 2 args={...}. There are three constructs (\csname and \pgfutil@ifundefined) with

pgfp@symb@coords@#1@...

that can be replaced by

pgf@symb@coords@#1@\detokenize\expandafter{...}

But I stop here, because Jake has already provided a much more elegant version for generating the diagram without needing symbol coordinates.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.