Answers for "matplotlib pie chart move autotext"

0

matplotlib pie chart move autotext

for patch, txt in zip(patches, autotexts):
    # the angle at which the text is located
    ang = (patch.theta2 + patch.theta1) / 2.
    # new coordinates of the text, 0.7 is the distance from the center 
    x = patch.r * 0.7 * np.cos(ang*np.pi/180)
    y = patch.r * 0.7 * np.sin(ang*np.pi/180)
    # if patch is narrow enough, move text to new coordinates
    if (patch.theta2 - patch.theta1) < 10.:
        txt.set_position((x, y))
Posted by: Guest on June-16-2021

Code answers related to "matplotlib pie chart move autotext"

Python Answers by Framework

Browse Popular Code Answers by Language