# How to use sansmath to specify the font for tick label in pgfplots with xelatex?

I learned from this answer that the package sansmath can be used to change the font of tick label by setting option tick label style. Now I want to set the tick label font to be sans serif font while other fonts such as legend font and label font are still serif fonts. I use xelatex and unicode-math. How can I achieve this?

\documentclass{article}
\usepackage{sansmath}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.16,
tick label style={font=\sansmath\sffamily},
}
\usepackage{unicode-math}
\setmathfont{TeX Gyre Termes Math}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addlegendentry{$n=1$};
\end{axis}
\end{tikzpicture}
\end{document}


In the above example, the tick label font is in the italic form. I want to make only the tick label font is sans serif and all other positions are still serif fonts.

I do not know if I am on the right track, and will be happy to delete this. I also do not have \setmathfont{TeX Gyre Termes Math} installed, but hope this is not too relevant. I am wondering if you are looking for

\documentclass{article}

\usepackage{sansmath}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.16,
xticklabel={\begin{sansmath}$\pgfmathprintnumber{\tick}$\end{sansmath}},
yticklabel={\begin{sansmath}$\pgfmathprintnumber{\tick}$\end{sansmath}},
}
\usepackage{unicode-math}
%\setmathfont{TeX Gyre Termes Math}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addlegendentry{$n=1$};

• @Ice0cean E.g. with xticklabel={\sffamily\pgfmathprintnumber{\tick}}, yticklabel={\sffamily\pgfmathprintnumber{\tick}},. – user121799 May 30 at 13:59