0

I have the following pie chart:

enter image description here

There are 2 labels on top overlapping. Is it possible to move a little bit up the first one? Moreover, how can I add a "connecting line" from the part of the pie to each label? Here is the code I'm using:

import matplotlib.pyplot as plt
import colorsys

labels = 'Control & Handling of Events', 'Arch. Structures & Viewpoints', 'Distribution of Components', 'Arch. Styles', 'Concurrency', 'Interaction & Presentation', 'Error & Exeption Handling', 'Fam. of Prog. & Frameworks','Security & Safety', 'Design Patterns', 'Arch. Design Decisions', 'Data Persistence'
sizes = [59, 40, 21, 21, 19, 17, 11, 8, 8, 5, 4, 4]
colors = ['#00305d','#003d69','#014b76','#025883', '#03668f','#04749c','#0481a9','#058fb6', '#069dc2','#07aacf','#08b8dc','#09c6e9']

fig1, ax1 = plt.subplots()
ax1.pie(sizes, colors=colors, labels=['%s, (%1.1f%%)' % (l, s) for l, s in zip(labels, sizes)], shadow=False, textprops={'color':"k", 'fontsize': 16}, startangle=90, pctdistance=0.8, labeldistance=1.05)
ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.
plt.show()

I tried to increase the size of the labels with textprops but increasing fontsize doesn't change the font.

Thanks for the help.

aripod
  • 55
  • 1
  • 14
  • 1
    Maybe this can help https://stackoverflow.com/questions/23577505/how-to-avoid-overlapping-of-labels-autopct-in-a-matplotlib-pie-chart – Mathix420 May 06 '21 at 09:28
  • Yes that was the first thing I did, but I'd rather keep the labels as shown in the figure, increase the size of them (they are barely readable in a pdf), separate them a bit further (first and second mainly) and draw lines to the pieces of the pie. – aripod May 06 '21 at 09:34
  • 2
    To draw lines between the text and the wedge: [How can I draw arrows around Matplotlib pie to point each label to their respective section in the circle?](https://stackoverflow.com/questions/67023749/how-can-i-draw-arrows-around-matplotlib-pie-to-point-each-label-to-their-respect) – JohanC May 06 '21 at 09:52
  • 1
    The last example at [the official tutorial](https://matplotlib.org/stable/gallery/pie_and_polar_charts/pie_and_donut_labels.html) rearranges the labels into vertical columns and connects them via a line to their wedge. You can e.g. leave out the surrounding text boxes. You can also set startangle=0, so the small wedges appear at the side instead of at the top, leaving more vertical room to avoid overlap. – JohanC May 06 '21 at 10:07
  • If you want to do it manually, you can use the following method to shift the first one to the top. `patches, texts = ax1.pie(...); x,y = texts[-1].get_position();texts[-1].set_position((x,y+0.1))` – r-beginners May 06 '21 at 13:04

0 Answers0