Studies of the adaptive significance of variation among conspecific populations often focus on a single ecological factor. However, habitats rarely differ in only a single ecological factor, creating a challenge for identifying the relative importance of the various ecological factors that might be maintaining local adaptation. Here we investigate the ecological factors associated with male body shape variation among nine populations of the poeciliid fish, Heterandria formosa, from three distinct habitats and combine those results with a laboratory study of three of those populations to assess the contributions of genetic and environmental influences to shape variation. Field‐collected animals varied principally in three ways: the orientation of the gonopodium, the intromittent organ; the degree of body depth and streamlining; and the shape of the tail musculature. Fish collected in the spring season were larger and had a more anteriorly positioned gonopodium than fish collected in autumn. Fish collected from lotic springs were larger and more streamlined than those collected from lentic ponds or tidal marshes. Some of the variation in male shape among populations within habitats was associated with population‐level variation in species richness, adult density, vegetative cover, predation risk, and female standard length. Population‐level differences among males in body size, position of the gonopodium, and shape of the tail musculature were maintained among males reared in a common environment. In contrast, population variation in the degree of streamlining was eliminated when males were reared in a common environment. These results illustrate the complicated construction of multivariate phenotypic variation and suggest that different agents of selection have acted on different components of shape.