1

How can I scale the ticklabels in Tikz to replicate the Matlab command

set(gca, 'XTick', xt, 'XTickLabel', xt.^3)

As an example, the xtick labels should be converted to the following

xtick={10,15,20,25,30,35},
xticklabels={1000,3375,8000,15625,27000,42875},

I want to have an automated procedure for this. Something like this:

xticklabel={$\pgfmathprintnumber{\tick^3}$}

Sadly, tikz can not parse this...

1

Just use xticklabel={\pgfmathparse{\tick^3}$\pgfmathprintnumber{\pgfmathresult}$} as in the following example. If you have huge numbers, you might want to use fpu.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xticklabel={\pgfkeys{/pgf/fpu}\pgfmathparse{\tick^3}$\pgfmathprintnumber{\pgfmathresult}$}]
\addplot [domain=0:35] {x};
\end{axis}
\end{tikzpicture} 
\end{document}

enter image description here

  • Thanks for your reply. If I replace your domain from "domain=0:8" to "domain=0:35", I get dimensions too large, how can I solve this? – user2978680 Nov 11 '18 at 15:42
  • @user2978680 I added instructions for that case. – user121799 Nov 11 '18 at 15:49

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.