Matplotlib - Bubble Graph and Pie Chart

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 19:- Matplotlib - Bubble Graph and Pie Chart

In Matplotlib, you can create a bubble graph (also known as a bubble chart) and a pie chart to visualize data. Both of these charts are useful for different types of data representation. Here's how you can create a bubble graph and a pie chart using Matplotlib:

Bubble Graph: A bubble graph displays data points as circles, where the size of each circle (bubble) represents a third dimension of the data.

In this example, the plt.scatter() function is used to create the bubble graph. The s parameter allows you to specify the sizes of the bubbles, and the c parameter sets the color of the bubbles.

Pie Chart: A pie chart displays data as slices of a circle, where each slice represents a portion of the whole.

In this example, the plt.pie() function is used to create the pie chart. The labels parameter sets the labels for each slice, and the autopct parameter adds percentage labels to each slice. The startangle parameter rotates the starting position of the chart.

Both bubble graphs and pie charts can be customized further by adjusting colors, labels, legends, and other visual elements to suit your specific data and visualization requirements.

Matplotlib is a versatile library that provides a wide range of charting options, making it a powerful tool for data visualization.

 

pythonCopy code

import matplotlib.pyplot as plt # Sample data categories = ['Category 1', 'Category 2', 'Category 3', 'Category 4'] sizes = [25, 30, 15, 30] # Create a pie chart plt.pie(sizes, labels=categories, autopct='%1.1f%%', startangle=90, colors=['red', 'green', 'blue', 'yellow']) plt.axis('equal')  # Equal aspect ratio ensures the pie chart is circular plt.title('Pie Chart') plt.show()

pythonCopy code

import matplotlib.pyplot as plt # Sample data x = [1, 2, 3, 4, 5] y = [10, 15, 8, 20, 12] sizes = [100, 200, 300, 400, 500] # Create a bubble graph plt.scatter(x, y, s=sizes, c='blue', alpha=0.5) plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Bubble Graph') plt.grid(True) plt.show()

2. Handling Data

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?