In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to draw pie charts and histograms with python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
# pie chart Often combined with structural analysis, import pandasimport numpyimport matplotlibimport matplotlib.pyplot as pltimport matplotlib.font_manager as font_manager# import data plot_pie=pandas.read_csv ('D://Python projects//reference data//6.3//data.csv') # is used to calculate the number of users of each brand and retain the sequence result=plot_pie.groupby (by= [' communication brand'] As_index=False) ['number'] .agg ({'number of users': numpy.size}) # use pop-up drawing% matplotlib qt# to set length and width resolution plt.figure (figsize= (20) Dpi=10) # method of obtaining the name of a font using an absolute path fontname=font_manager.FontProperties (fname= "C://Windows//Fonts//FZSTK.TTF") # set font font= {'family':fontname.get_name (),' size':20} matplotlib.rc ('font',**font) # set pie chart plt.axis (' equal') # draw pie chart plt.pie (result ['number of users] Labels=result ['Communications Brand'], autopct='%.2f%%') # sets the prominent part explode= (0.1 mine0.2, 0.3) plt.axis ('equal') plt.pie (result [' number of users'], labels=result ['Communications Brand], autopct='%.2f%%')
The result is:
Histogram:
# histogram import pandasimport matplotlibfrom matplotlib import pyplot as plt# sets font font= {'family':'SimHei',' size':15} matplotlib.rc ('font',**font) # Import data data_histogram=pandas.read_csv (' D://Python projects//reference data//6.5//data.csv') maincolor= (42 D://Python projects//reference data//6.5//data.csv') 256141) # draw preliminary histogram plt.hist (data_histogram. Number of users purchased, color=maincolor) plt.hist (data_histogram ['number of users purchased'], color=maincolor)
The result is:
# set the number of groups to 30plt.hist (data_histogram. Number of users purchased, bins= (30), color=maincolor)
The result is:
# drawing a waterfall diagram, that is, accumulating plt.hist (data_histogram. Number of users purchased, bins= (30), cumulative=True, color=maincolor)
The result is:
"how to use python to draw pie chart and histogram" content is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.