Tikz and exponential style tick label
This is not correct. It is, rather, a cleaner hack which does not fail with an error on compilation, as the code in the question does.
Following the example on page 805 of the manual, we define \mytypesetter
as follows:
\def\mytypesetter#1{% page 805
\tikzset{%
/pgf/number format/.cd,
sci,
sci generic={mantissa sep=,exponent={0^{##1}}}%
}%
\pgfmathprintnumber{#1}%
}
Since in this case the mantissa is always equal to 1
, setting mantissa sep
to an empty value and typesetting to exponent as 0^{<value>}
rather than 10^{<value>}
should give the result we want.
This is obviously not a good solution, but only a hack, because this is far from semantic mark-up. Indeed, it mixes format and content in an especially horrible way.
We can, however, then say
tick typesetter/.code=\mytypesetter{##1},
to produce the required output, if I've understood the desiderata correctly.
If you prefer to configure this all in the one place, you can do so but you must distinguish between the first argument being passed to tick typesetter
and the first argument being passed to /pgf/number format/sci generic
. You do not want to pass the former to the latter else you will end up with the entire number formatted in the exponent, in addition to the mantissa part and the separator preceding it.
y axis={
logarithmic,
ticks and grid={
step=1,
minor steps between steps=8,
tick typesetter/.code={%
\tikzset{%
/pgf/number format/.cd,
sci,
sci generic={mantissa sep=,exponent={0^{####1}}}%
}%
\pgfmathprintnumber{##1}
}
},
},
I would tend not to do this as I find this much harder to read than the first version which splits out the code formatting the number from the processing of the number in the axis definition. But the second version produces the same output if you prefer it for some reason.
Complete code:
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{datavisualization,datavisualization.formats.functions}
\def\mytypesetter#1{% page 805
\tikzset{%
/pgf/number format/.cd,
sci,
sci generic={mantissa sep=,exponent={0^{##1}}}%
}%
\pgfmathprintnumber{#1}%
}
\begin{document}
\begin{tikzpicture}
\datavisualization [
scientific axes,
all axes={length=6cm},
x axis={
ticks and grid={
step=2,
minor steps between steps=1
},
include value={0,20},
},
y axis={
logarithmic,
ticks and grid={
step=1,
minor steps between steps=8,
tick typesetter/.code=\mytypesetter{##1},
},
},
visualize as line
]
data[separator=\space] {
x y
0 1E1
5 1E2
10 1E3
15 1E4
20 1E5
}
;
\end{tikzpicture}
\end{document}