How to include matplotlib pgf into Latex document?

When I include pgf generated by Matplotlib into latex document. I got the error of

Undefined control sequence. \mathdefault

Which is used by matplotlib. What’s the best way to solve this issue? Do I just include

\newcommand{\mathdefault}[1][]{}

in my Latex file? I’m reluctant to doing so as I don’t see any mentioning of this requirement. I followed several tutorials on including a matplotlib pgf in latex. They all don’t include this newcommand def and have the same issue. But the writers seem not to notice it. Have I done something silly or there is some breaking change in matplotlib lately?