Editing Tikz Axis
Hystrelius May 03, 2025 [Software] #latex #tikzOne of the problems which I struggled a lot with Tikz was trying to scale the axis of a plot, as it would end up choosing the most obscure scales like $10^2$.
So, I compiled all my fixes that I found, which turns a graph like:
(Seriously, Tikz what is going on here!? – there are label collisions, weird scales)
Into a graph like:
This involves editing the “frontmatter” of the tikz file to force it to change scales.
This is what my old front-matter looked like:
\begin{axis}
With the config telling Tikz the ranges of the $x$ and $y$ axis, but importantly nothing about the scale. (The “scale only axis” prevents the graph from warped).
To fix this we need to force Tikz to scale for us,
scaled x ticks=base 10:-3,
scaled y ticks=base 10:3,
These functions basically times every $x$ tick value by $10^{-3}$ and every $y$ tick value by $10^{3}$, which shifts into more respectable ranges. To stop a little $10^{3}$ from floating around next to the axis, we can overload tikz to remove that pesky little number:
xtick scale label code/.code= ,
ytick scale label code/.code= ,
This basically forces the little scale label to be blank.
So, this is what the final front-matter looks like:
\begin{axis}
And doing logarithmic scales is very similar,
xmode=log,
ymode=log,
So, there you go!
P.S., making these graphs
I made these graphs through importing CSV data into MatLab and then using the matlab2tikz
package to export the data into a Tikz file.