Digestize

In this short post, we look at how to create a pie chart as follows:

Pie chart with percentages and labels

The key code blocks are as follows:

The function to compute the percentages:

def my_autopct(pct):
return ('%.2f' % pct)

The function to assign labels:

def get_new_labels(sizes, labels):
new_labels = [label for size, label in zip(sizes, labels)]
return new_labels

How do you show the labels only for the significant shares (especially if we have many entries in the bar chart)?

--

--

This short post demonstrates how you can add the count values to the top of the bars in a bar chart.

Bar chart annotated with the counts

Here’s the code snippet:

The high-level idea is as follows:

  1. Create the chart and save to ax
  2. Use the following code snippet to annotate with the counts:
for…

--

--

Digestize

Digestize

#probability #statistics #ML #DL #coding #security #building #digest