In this work, a general spherical harmonics method for the extraction of anisotropic pair distribution functions (PDFs) is described. In the structural study of functional crystallized materials, there is an urgent need for investigation of local structures under the application of external stimuli, such as an electric field and stress. A well established technique for local structural studies is PDF analysis, but the extraction of X-ray PDF data is usually based on angular integrations of isotropic X-ray structure functions, which is no longer valid for the anisotropic responses of materials under orientation-dependent stimuli. Therefore, an advanced spherical harmonics method has been developed, to transform 2D X-ray total-scattering data into anisotropic PDF data on the basis of the 3D diffraction geometry and a Fourier transform. The electric-field-induced local structural change in PbZr0.54Ti0.46O3 ceramics is presented to demonstrate the effectiveness of this method.