This visage of mathematicians among the general public is fairly new I think; it may have existed in some intellectual circles but was not common among regular people. It’s fairly common to read about the lives of mathematicians well into the 19th or even early twentieth century where as children or young adults who excelled at mathematics, their parents or guardians attempted to dissuade them from pursuing mathematics as a career because of the difficulty in obtaining lucrative jobs in mathematics unlike fields like law, engineering, etc. This was the case not only in impoverished countries but in western Europe as well.
Side note: it’s often the case that mathematicians and scientists are perceived only in terms of their research work instead of their personal lives or just other aspects of their lives. How many people on sites like HN or Reddit, would still perceive, for example, Euler the same way if they learned that along with being a genius in mathematics, he was also a religious fundamentalist who was known for annoying his colleagues with his incessant preaching? My point is not to suggest that this takes away from his mathematical work, but it is an indication that the perception people have about at least some of these figures is not based on their reality.