For pyrite, FeS2, both the imaginary and real parts of the anisotropy of the iron atomic scattering factor are experimentally determined as functions of the x-ray energy near the iron K-edge and compared with ab initio calculations. The anisotropy appears due to the deformations of the electronic states induced by the asymmetric atomic environment and thus provides a quantitative measure of these deformations. As a consequence, reflections expected to be forbidden by screw-axis or glide-plane symmetry operations can be excited, with structure factors being proportional to the anisotropy. The azimuthal angle dependencies and energy spectra of such anisotropy-induced "forbidden" reflections are studied and the phase of the anisotropy is determined from interferences of the forbidden reflections with different multiple-wave reflections. The energy dependencies of the real and imaginary parts of the anisotropy are shown to be in good agreement with theoretical results obtained from two different approaches, i.e., the full multiple-scattering method employing a cluster muffin-tin potential and pseudopotential ab initio calculations. It is found that the anisotropy in pyrite is much more sensitive to the Fe environment than the average absorption coefficient.