In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to achieve Python pie chart, I hope you will learn something after reading this article, let's discuss it together!
1. Ordinary pie chart
The drawing effect of the ordinary pie chart is as follows:
The complete code is as follows:
#-*-coding:utf-8-*-# declare that the encoding format is utf-8import matplotlib as mplimport matplotlib.pyplot as pltmpl.rcParams ["font.sans-serif"] = ["SimHei"] # specify the font as SimHei, which is used to display Chinese If Ariel, Chinese garbled mpl.rcParams ["axes.unicode_minus"] = False# is used to normally display the negative sign g = ["SCI Zone 1", "SCI Zone 2", "SCI Zone 3", "SCI Zone 4", "Chinese Core"] c = ["r", "b", "g", "y", "c"] t = [1237, 3134, 3456, 2345, 1245] # the project name, color code, and specific value plt.pie of each component of the pie chart are defined above. Autopct= "% 3.1f%", startangle=60,colors=c) # autopct= "% 3.1f%%" represents three digits, one of which is a decimal place. Plt.title ("figure 8 Statistics of papers published in recent three years") plt.show ()
PS: if you need Python learning materials, you can add the group below to go to the free administrator to get it.
two。 Split pie chart
Just add the explode parameter to line 15 of the code on the basis of the "1. Normal pie chart" code. The supplementary code is as follows:
# split Pie Chart explode= (0.1 startangle=60,colors=c 0.1) plt.pie (tGrad explode explodeg labelschart startangle=60,colors=c)
The drawing effect is as follows:
If you set the interval for only one element in the explode parameter, the other interval is 0, for example:
Explode = (0. 1, 0, 0, 0, 0, 0)
The effect is as follows:
The code is as follows:
#-*-coding:utf-8-*-# declare that the encoding format is utf-8import matplotlib as mplimport matplotlib.pyplot as pltmpl.rcParams ["font.sans-serif"] = ["SimHei"] # specifies that the font is SimHei, which is used to display Chinese. If Ariel, Chinese garbled mpl.rcParams ["axes.unicode_minus"] = False# is used to normally display the negative sign # data elements= ["SCI Zone 1", "SCI Zone 2", "SCI Zone 3", "SCI Zone 4" "Chinese Core"] T1 = [1237 Magne2134] T2 = [120134456845245] # Color outer_colors= ["r", "b", "g", "y", "c"] inner_colors= ["r", "b", "g", "y", "c"] wedges1,texts1,autotexts1=plt.pie (T1 wedges1,texts1,autotexts1=plt.pie autopct = "% 3.1f%", radius=1,pctdistance=0.85,colors=outer_colors,textprops=dict (color= "w"), wedgeprops=dict (width=0.3,edgecolor= "w")) wedges1,texts1,autotexts2=plt.pie (T2) Autopct= "% 3.1f%%", radius=0.7,pctdistance=0.75,colors=inner_colors,textprops=dict (color= "w"), wedgeprops=dict (width=0.3,edgecolor= "w")) plt.legend (wedges1,elements,fontsize=12,title=' Paper Grade', loc='center left',bbox_to_anchor= (0.91 plt.setp 0.3)) plt.setp (autotexts1,size=15) plt.setp (autotexts2,size=15) plt.setp (texts1) Size=12) plt.title ('papers published by our university and its partners') plt.show () has finished reading this article I believe you have a certain understanding of "how to achieve pie chart in Python". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
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.