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}
I assume that you are looking for y tick label style={/pgf/number format/sci}
. See also Chapter 4.13.1 (Frequently Used Number Printing Settings) in the current pgfplots
manual ( I find it a bit difficult for beginners since this is tikz
stuff as I understand it and not pgfplots
-specific), see also* manual of pgfplotstable
Chapter 2.7 (Number Formatting Options).
I do not know how to get the common mantissa
sepearte from the
ticks and at the top of the axis: Any experts here?
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
% Based on http://pgfplots.sourceforge.net/gallery.html
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel={$f(x) = x^2 - x +4$},
% Added
y tick label style={/pgf/number format/sci},
]
% use TeX as calculator:
\addplot {x^2 - x +4};
\end{axis}
\end{tikzpicture}
\end{document}
*"The options related to number printing as such are described in all detail in the manual for PgfplotsTable,
which comes with pgfplots."
Best Answer
I think
or similar will solve both problems. You can do
scaled x ticks
orscaled y ticks
separately, and the number after the colon is the common exponent that you're factoring out.(Note that this is incompatible with your current
y tick label style
, so you will need to remove that before this works.)