The following is the explanation of the code:
- Depts is the list of departments in the organization. rp and ra are lists of planned expenses and actual spending by department.
- plt.figure(figsize=(10,6)) sets the figure size. plt.subplot(polar=True) sets polar projection.
- The pyplot method accepts only radians as input, hence we need to divide 2 x np.pie (which is equivalent to 360 degrees) radians into number of departments equally, to get the angle coordinates for each of the departments. np.linspace(0, 2 * np.pi, len(rp)) does this computation.
While the coordinates need to be given in radians, the degree equivalent is easy for visualization. To convert radians to degrees, you can use np.degrees (theta).