The ability to sensitively image electric fields is important for understanding many nanoelectronic phenomena, including charge accumulation at surfaces1and interfaces2and field distributions in active electronic devices3. A particularly exciting application is the visualization of domain patterns in ferroelectric and nanoferroic materials4,5, owing to their potential in computing and data storage6–8. Here, we use a scanning nitrogen-vacancy (NV) microscope, well known for its use in magnetometry9, to image domain patterns in piezoelectric (Pb[Zr0.2Ti0.8]O3) and improper ferroelectric (YMnO3) materials through their electric fields. Electric field detection is enabled by measuring the Stark shift of the NV spin10,11using a gradiometric detection scheme12. Analysis of the electric field maps allows us to discriminate between different types of surface charge distributions, as well as to reconstruct maps of the three-dimensional electric field vector and charge density. The ability to measure both stray electric and magnetic fields9,13under ambient conditions opens opportunities for the study of multiferroic and multifunctional materials and devices8,14.