Based on the tight-binding method, we investigate the energy spectrum and localization of electronic states in 2DEG subjected to a spatially local gradient magnetic field. Generally, such structure can be obtained easily by placing ferromagnetic stripes on the surface of semiconductor heterojunction. Considering the numerical accuracy, the actual calculated profiles of magnetic field are used in this work. By adjusting the width of stripe d and the amplitude of magnetic field, the energy spectra and the square root of probability density are obtained. The former is convergent when the width d is zero or becomes very large and the latter shows that the ground states are localized at the center of 2DEG. For large B and small width d, the energy level crossing between the ground and the first excited states would cause the pattern of probability density splitting into two parts. We also study the case of four stripes on the top of 2DEG. For emphasizing the effect of magnetic field, the harmonic potential is removed. The low energy levels tend to bundle themselves into groups because there exists three similar magnetic potential wells in this situation. All these findings will help us to further understand the electronic properties of 2DEG in varying magnetic field.