How to Position Tick Scale Labels in pgfplots
At a glance
- 1. Identify the label
A tick scale label is the multiplier, such as ×10³, shown when pgfplots scales tick values.
- 2. Set its style
Use the x or y tick scale label style key to adjust the multiplier’s position and appearance.
- 3. Move tick labels separately
Use xticklabel pos or yticklabel pos for the individual numbers beside the axis.
In pgfplots, “tick scale label” usually means the multiplier printed when tick values are scaled, such as the ×10³ accompanying values 0, 1, 2, and 3. You can position that multiplier with an axis-specific style key. If you mean the individual tick numbers instead, use the separate tick-label position keys described below.
Position the multiplier from scaled ticks
When pgfplots scales tick values, it draws a scale label alongside the axis. Use x tick scale label style for the multiplier associated with the x-axis, or y tick scale label style for the y-axis. These style keys accept normal TikZ node options, including at, anchor, and shifts.
Here is a complete example that scales y ticks by 1,000 and places the scale label above the upper-left corner of the plot:
\documentclass[tikz,border=3pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=8cm,
height=5cm,
ymin=0,
ymax=4000,
ytick={0,1000,2000,3000,4000},
scaled y ticks=base 10:3,
y tick scale label style={
at={(axis description cs:0,1)},
anchor=south west,
xshift=2pt,
yshift=2pt,
},
]
\addplot coordinates {(0,0) (1,1000) (2,2000) (3,3000) (4,4000)};
\end{axis}
\end{tikzpicture}
\end{document}
The scaled y ticks=base 10:3 setting expresses the tick values in thousands. The at option chooses a location relative to the axis description area, whose lower-left and upper-right corners correspond to (0,0) and (1,1). The anchor and shifts control how the scale-label node sits at that location. Adjust the coordinates and shifts to suit your layout; a scale label’s ideal position depends on the axis size and the other labels around it.
For an x-axis multiplier, use scaled x ticks and x tick scale label style instead. You can also change the multiplier’s appearance with ordinary node options, for example font=\small or text=red.
Move the individual tick numbers
The multiplier style does not reposition the numeric tick labels themselves. To move those labels to another side of the plot, set xticklabel pos or yticklabel pos:
\begin{axis}[
xticklabel pos=top,
yticklabel pos=right,
]
The corresponding values are top or bottom for x tick labels, and left or right for y tick labels. For instance, yticklabel pos=right puts the y-axis numbers on the right side of the plotting area. If you also want the axis line on that side, configure the line separately with axis y line=right.
Common mistakes
- Changing the wrong label:
yticklabel posmoves the individual y tick numbers;y tick scale label stylestyles the multiplier. They do not substitute for each other. - Moving the label but not the axis: The scale-label style affects the multiplier node only. Use
axis x lineoraxis y linewhen you want to move an axis line. - Assuming a multiplier will always appear: pgfplots may not generate a scale label for every data range or tick-scaling configuration. Check that scaling is enabled and that your chosen scaling makes sense for the values.
- Placing the node without leaving room: A scale label moved beyond the axis can overlap surrounding text or be clipped. Adjust its
atcoordinate, anchor, and shifts, and allow enough space in the figure.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.