You might have a fair point. I am, however, empirically convinced (but have no data) that the examples you are quoting are a very small portion of their respective professional market population, whereas, always empirically, I'd say that the amount of software professionals who willingly choose to be underpaid purely because of their attraction to some kind of work is much much higher, probably in the 30%+.
Someone doing pediatrics might have been better off skipping med school and being a nurse practitioner, or a taxi programmer. Or when going through it, specializing instead in dermatology. Now imagine your town without any pediatricians and GPs and emergency staff ;-)