# Adjust font size of axis labels in tikzfigures based on scaling of the figure

I have a rather large document, containing several tikz-figures. Those are separated in their own files, with file AxisImage.tex as example:

\begin{tikzpicture}
\begin{axis}
[ylabel = y,
xlabel = x]
\addplot table [x=a, y=c, col sep=comma] {data.csv};
\end{axis}
\end{tikzpicture}


To reduce compilation time, I compile them as standalone-figure using

\documentclass{standalone}
\begin{document}
\input{AxisImage}
\end{document}


into their respective pdf-files. To keep all includes and adjustments at a single place for both the main document and the figures in one place, I generated a common header, containing

\usepackage{pgfplots}
\usepackage[english]{babel}
\usepackage{blindtext}


Afterwards, everything is put together in the main document:

\documentclass{article}
\begin{document}
\blindtext[1]
\begin{figure}[htpb]
\centering
\includegraphics[width=0.4\linewidth]{image_generator}
\caption{This is a figure}
\end{figure}
\blindtext[2]
\end{document}


Now I got the request to make the axis labels the same font size as the caption of the figure, regardless of the scaling of the figure (i.e. if I increase the size of the figure, the font size has to be reduced).
I could do that by try and error for every figure size change, but it gets annoying quite fast. Are there other possibilities, such as macros which could do that for me (placed in the common header)?

You can use external library to reduce compilation time and set the size of pgfplots figure without changing label font size as well.

Note that with external library loaded, you need to compile the tex file with, for example, pdflatex -shell-escape main.tex.

An example:

\documentclass{article}
\usepackage{pgfplots}
\usepackage[english]{babel}
\usepackage{blindtext}

\usetikzlibrary{external}
% option -shell-escape required
\tikzexternalize
\pgfplotsset{compat=1.17}

\begin{document}
\blindtext[1]
\begin{figure}[htpb]
\centering
\begin{tikzpicture}
\begin{axis}[
ylabel = y,
xlabel = x,
% set size of pgfplots figure
width=.4\linewidth,
% set label font
label style={font=\normalfont}
]