We investigate the thermal entanglement of two-qubit anisotropic Heisenberg XY model in the presence of an external nonuniform magnetic field B along the z-axis. Concurrence, the measure of entanglement is calculated and its property is studied in different cases. Two best models, Ising model under a uniform magnetic and isotropic model in a nonuniform magnetic field, are discovered. In the two models, the critical temperature Tc (above which there is no entanglement) can be enhanced and its concurrence is maximal.