Donut Chart

Using the iris dataset from scikit-learn, create a donut chart showcasing the distribution of samples across species. Customize the width of the ring and provide appropriate labels.

Example Output:

A donut chart is a modified version of a pie chart. After computing the counts for each species, use the pie function from Matplotlib to plot a pie chart and modify its appearance to look like a donut by setting the wedgeprops parameter.

import matplotlib.pyplot as plt
from sklearn.datasets import load_iris

def donut_chart():
    iris = load_iris()
    species_counts = [sum( == target) for target in range(3)]
    plt.pie(species_counts, labels=iris.target_names, startangle=90, wedgeprops={'width': 0.3})
    plt.title("Donut Chart of Iris Species Distribution")

# Example usage


© Let’s Data Science


Unlock AI & Data Science treasures. Log in!