An improved butterfly optimization algorithm (IBOA) is proposed to solve the problems of slow search speed, low search accuracy and easy to fall into local optimization when the basic butterfly optimization algorithm (BOA) is used in the 3-D path planning of unmanned aerial vehicle (UAV). In the global search phase, a logarithmic adaptive inertia weight strategy and a dynamic update adjustment strategy are proposed to improve the global search ability and search accuracy of the algorithm. At the same time, in the local search phase, a dynamic probability cosine selection strategy is proposed to increase the diversity of location updates and avoid falling into local optimization. Firstly, in order to test the optimization performance of the improved algorithm and the basic algorithm, the simulation comparison is carried out on some standard multivariate functions. The comparison results show that the improved algorithm has strong optimization ability for complex functions and can find the global optimal solution in a shorter time. Then, the peak simulation function is used to model the three-dimensional path planning of UAV, and the improved algorithm is applied to the path planning. The track planning effects under different complexity environments are compared by MATLAB simulation. The simulation experiments show that under the same experimental conditions, the comprehensive fitness value of the optimization algorithm is reduced by 21.9% compared with the basic butterfly algorithm, which has the advantages of fast search speed and high search accuracy. It can effectively guide the UAV to complete the task of autonomous navigation and obstacle avoidance in a 3-D environment.