The effect of magnetic fields on convection at the surfaces of cool stars can be explored by comparing the results of detailed numerical experiments with high-resolution solar observations. We have investigated non-linear three-dimensional magnetoconvection in a fully compressible perfect gas. In this paper we study the effect of an imposed magnetic field on the pattern of convection in a deep stratified layer. When the field is strong enough to dominate the motion we find steady convection with rising plumes on a deformed hexagonal lattice, and a magnetic network at the upper boundary. This gives way to spatially modulated oscillations for weaker fields. As the field strength is further reduced the oscillations become more violent and irregular, and their horizontal scale increases. Magnetic flux moves rapidly along the network that encloses the ephemeral plumes; when the imposed field is relatively weak, intense fields appear at junctions in the network, where the magnetic pressure is comparable to the gas pressure and an order of magnitude greater than the dynamic pressure. This behaviour is related to convection in sunspots and plages and to the structure of intergranular magnetic fields on the Sun.