In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is about creating pie charts using Matplotlib. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
background introduction
You'll learn how to use Matplotlib to create pie charts, which are ideal for displaying data in a way that clearly shows the proportions of each category. We will learn how to draw pie charts, customize its appearance and more. Let's get started...
Getting Started Examples
Let's start with the simplest pie chart example, looking at apples and oranges as a percentage of sales:
from matplotlib import pyplot as pltfrom matplotlib import rcParams#Set chart font to prevent Chinese garbled rcParams <$'font.family'] = 'Microsoft YaHei'rcParams <$'font.sans-serif'] = ['Microsoft YaHei']#Set chart style plt.style.use ('fivethirtyeight ')#Define pie chart data slices = [60,40]#Define data representation labels = [' apple','orange']#Construct pie chart plt.pie(slices,labels=labels)#Set title layout display plt.title("My first pie chart? ")plt.tight_layout()plt.show() Run result:
Comprehensive case
Next we look at a complete pie chart example, drawing a pie chart of programming language usage and customizing the pie chart appearance and style:
from matplotlib import pyplot as plt from matplotlib import rcParams#Set chart font to prevent Chinese garbled rcParams <$'font.family'] = 'Microsoft YaHei'rcParams <$'font.sans-serif'] = ['Microsoft YaHei']#Set chart style plt.style.use ('fivethirtyeight ')#defines the number of usage of the development language slices = [59219, 55466, 47544, 36443, 35917]#development language label names labels = [' JavaScript','HTML/CSS', 'SQL',' Python','Java']#sets python language to pop up 10% of the distance in pie chart display explode = [0, 0, 0, 0.1, 0]#Start constructing pie chart #shadow: show shadows to look 3D #startangle: rotate pie chart 90 degrees counterclockwise from x-axis #autopct: show percentage of data #wedgeprops: set edge line color plt.pie(slices, labels=labels, explore = explore, shadow=True,startangle=90,autopct='%1.1f%%', wedgeprops={'edgecolor':'black'})
plt.title("Programming Language Usage Scale Diagram")plt.tight_layout()plt.show() Thank you for reading! About "how to use Matplotlib to create pie chart" this article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.