# Bar plots in sans serif font

I want to typeset my bar plots with a sans serif font (using LuaTeX). I tried many options that I found searching the manual and the internet. None of them solved my problem---using different fonts than CM; with CM it works!

The same MWE shows different results in the PDF depending on the engine (PDFTeX vs. LuaTeX).

\documentclass{scrartcl}
\usepackage{%
sansmath%
,MinionPro%
}
\usepackage{pgfplots}
\pgfplotsset{%
/tikz/font=\sansmath\sffamily
}
\usepackage{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xbar,
xlabel={a--d},
symbolic y coords={a,b,c,d},
ytick=data,
nodes near coords, nodes near coords align={horizontal},
]
(45,a)
(20,b)
(1,c)
(5,d)
};
\end{axis}
\end{tikzpicture}
\end{document}


Plot:

\documentclass{scrartcl}
\usepackage{%
sansmath%
}
\usepackage{fontspec}
\setmainfont[%
BoldFont={MinionPro-Bold}%
,ItalicFont={MinionPro-It}%
,BoldItalicFont={MinionPro-BoldIt}%
,Numbers=OldStyle%
]{MinionPro-Regular}

\setsansfont[%
Scale=MatchLowercase%
,Numbers=OldStyle%
\usepackage{pgfplots}
\pgfplotsset{%
/tikz/font=\sansmath\sffamily
}
\usepackage{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xbar,
xlabel={a--d},
symbolic y coords={a,b,c,d},
ytick=data,
nodes near coords, nodes near coords align={horizontal},
]
(45,a)
(20,b)
(1,c)
(5,d)
};
\end{axis}
\end{tikzpicture}
\end{document}


Plot:

Here are some of the pgfplotsset options I already tried (and noted down):

\pgfplotsset{%
%  ,tick label style = {font=\sansmath\sffamily}%
%  ,tick style = {font=\sansmath\sffamily}
%  ,every axis label = {font=\sansmath\sffamily}%
%  ,every axis/.style={font=\sansmath\sffamily}%
%  ,xticklabel={$\pgfmathprintnumber{\sansmath\tick}$}%
,/tikz/font=\sansmath\sffamily
%  ,legend style = {font=\sansmath\sffamily}%
%  ,label style = {font=\sansmath\sffamily}%
}


Best regards Christoph

-
Not an answer, but if a deadline is looming could you generate the image in a standalone document, and then include the image for the LuaTeX run? –  cmhughes Nov 25 '12 at 22:14
@cmhughes Good idea! But I did not have a working solution for PDFTeX (numerics were printed italic) since sebschub posted his solution. –  typokurz Nov 27 '12 at 15:18

Do you use the MinionPro and MyriadPro versions from FontPro with pdflatex? With these packages, you do not need sansmath, it is already incorporated in MdSymbol which is needed by MyriadPro. The following set-up works with pdflatex:

\documentclass{scrartcl}
\usepackage{MinionPro}
\usepackage{pgfplots}
\pgfplotsset{%
/tikz/font=\mathversion{sans}\sffamily
}
\usepackage{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xbar,
xlabel={a--d},
symbolic y coords={a,b,c,d},
ytick=data,
nodes near coords, nodes near coords align={horizontal},
]
(45,a)
(20,b)
(1,c)
(5,d)
};
\end{axis}
\end{tikzpicture}
\end{document}


This produces

-
No, I use the fonts provided with Adobe Reader with LaTeX support from developer.berlios.de/projects/minionpro. MyriadPro.sty provided by this project does not know the sansmath option. Do your files support the fonts from Adobe Reader? –  typokurz Nov 27 '12 at 15:32
@typokurz My scripts are based on the project you mentioned and work well with any version of the fonts. I don't provide prepared metrics, though, so one has to use the bash scripts to create them. My MinionPro.sty is very similar to the original one, only small bug fixes and extensions. I'm sure, however, that the original MinionPro project doesn't provide any support for Myriad Pro. My MyriadPro support offers features similar to the ones of MinionPro including proper maths support and the functionality to use two different maths fonts in one document (with the setup above). –  sebschub Nov 27 '12 at 16:33
Thanks for your answer! But maybe there's somebody else with a solution for LuaTeX? –  typokurz Nov 28 '12 at 18:09
My problem was solved by Herbert here using the unicode-math package and \setmathfont. Another approach was offered by egreg here by changing the mathcode of the digits.