How and why are the spectacular colours at Yellowstone park generated?

The yellow stone canyon that gave Yellowstone its name is made from sandstone, which can have a wide variety of colors based on (1) the colors of the sand from which the rock was made and (2) the amount of metallic contaminants (chiefly iron) within the stone.