In the late-19th century, when margarine began to emerge as a cheap substitute for natural butter, manufacturers added a yellow dye to make it look more like butter so it would be more acceptable to consumers.
Dairy farmers objected, and lobbied Congress to pass the Oleomargarine Act of 1886, which imposed a penalty tax on any margarine that was colored to look like butter. The law also gave the dairy farmers the explicit right to use their own color additives. At the beginning of the 20th century, these discriminatory color laws were widespread: 32 states had banned yellow margarine; some had even forced manufacturers to dye their product an unappetizing pink.
Restrictive Federal legislation was repealed in 1950 after margarine gained in popularity as it found political allies, and as nutritionists, advertisers and home economists began to portray it differently. Margarine was no longer eaten only by poor people. In 1967, Wisconsin became the last state to repeal its anti-color law. (info from Slate and Jstor)