Butterflies will stop and drink nectar from nearly any flower that attracts their attention and provides them with adequate fuel. When it's time to lay eggs, though, these same insects become very particular. Only the right plants will satisfy their finicky tastes.
The search for these plants begins once a female butterfly mates. The female will land on a leaf and inspect the leaf using its antennae or receptors in its feet (brush-footed butterflies like the Monarch have special front legs just for this purpose). But rather than identifying the plant to species, the female is testing the plant for those characteristic chemicals needed to nourish (and protect) its caterpillars.
Ironically, the chemicals that females seek were originally produced to deter feeding by caterpillars. In order to protect themselves from defoliation, plants create toxic chemicals. When a species of insect develops the ability to counteract these toxins, it can specialize in feeding on the plant without competition from other animals. In addition, some caterpillars store and concentrate plant toxins, which makes them distasteful to predators.
So it's important to know which plants female butterflies want for their eggs. In most cases, these are native plants. Musk Mallow, for example, is popular with all three Painted Lady species in the East, while Showy Milkweed attracts Monarchs and Queens in the West. But introduced species sometimes work, too. The Anise Swallowtail favors Wild Anise, which Europeans brought to North America some 200 years ago.
Besides the right plants -- see the handy regional guides for butterfly gardeners across the country -- caterpillars need places to pupate. Since most caterpillars wander away from their food plants to pupate, it's a good idea to leave a few dried stalks and tangled places for them. Also, some species like to pupate (or spend the winter as caterpillars) in the leaf litter near their food plants, so don't rake all of this material away. And of course, don't use pesticides in your butterfly garden.