I am trying to normalize the axis of a pgfplots graph by certain values, something like 2000
for the y-axis and 19099
for the x-axis. The y-axis looks nice as expected, but the x-axis being scaled by a not nice number, produces tick labels that are something like 0.52
, 1.05
, 1.57
, etc. rather than 0.5
, 1
, 1.5
etc.
Is there a way to scale the axis but still place the ticks at nice locations automatically?
Minimal working example:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin = 0,xmax = 70000,
ymin = 0,ymax = 5000,
scaled x ticks=manual:{}{\pgfmathparse{(#1)/(19099)}},
scaled y ticks=manual:{}{\pgfmathparse{(#1)/(2000)}},
]
\end{axis}
\end{tikzpicture}
\end{document}
UPDATE
Trying @Jake approach, gives me errors when I plot a function within my axis, see following:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin = 0,xmax = 70000,
ymin = 0,ymax = 5000,
domain=0:70000,
x coord trafo/.code={
\pgfkeys{/pgf/fpu=true}
\pgfmathparse{(#1)/(19099)}
\pgfkeys{/pgf/fpu=false}
},
y coord trafo/.code={
\pgfkeys{/pgf/fpu=true}
\pgfmathparse{(#1)/(2000)}
\pgfkeys{/pgf/fpu=false}
},
% scaled x ticks=manual:{}{\pgfmathparse{(#1)/(19099)}},
% scaled y ticks=manual:{}{\pgfmathparse{(#1)/(2000)}},
]
\addplot {2000+0.001*(x/60)^2};
\end{axis}
\end{tikzpicture}
\end{document}
This produces errors, such as: “! Illegal unit of measure (pt inserted).`
Best Answer
The
scaled x ticks
key only acts after the tick positions have already been determined, so they're not the way to go here. Instead, you should transform your coordinate system usingx coord trafo/.code
andy coord trafo/.code
.Note that for values as large as yours, you'll need to switch on the
fpu
library in the.code
. When usingxmin
,xmax
, etc., thefpu
library needs to be deactivated after the calculation, but when plotting mathematical expressions, the library may not be deactivated. This is a bit cumbersome: You'll have to\pgflibraryfpuifactive
to decide whether we're in a context where the libary should be switched on and off, or left as it is: