Jesse E. answered 04/27/19
Masters in Chemistry and Bachelors in Biology
When a molecule absorbs light, our perception of that molecule's color is determined based on the wavelength of light that is not absorbed by that molecule. For example, let's examine carrots.
To us, carrots are orange. However, the carrot has pigments of beta carotene that absorb blue light and reflects all other wavelengths of light. Because orange is complementary to blue on the color wheel we learned in elementary school, our brain perceives the carrot as orange.
For chemical compounds, chemists know which chemical structures will be absorbed by which wavelengths. So if they want to want to prepare a compound with a yellow color, they will use a compound that absorbs its complimentary color of purple.