Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to draw Pareto Map with Python

Shulou Source: shulou.com Published: 2022-06-01 20:15:04 10月28日 Update

This article mainly explains "how to draw Pareto map with Python". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to draw a Pareto map with Python.

# Random colors, from fakerdef rand_color ()-> str: return random.choice (["# c23531", "# 2f4554", "# 61a0a8", "# d48265", "# 749f83", "# ca8622", "# bda29a", "# 6e7074", "# 546570") "# c4ccd3", "# f05b72", "# 444693", "# 726930", "# b2d235", "# 6d8346", "# ac6767", "# 1d953f", "# 6950a1",]) df_origin = pd.DataFrame ({'categories': ["vegetables", "fruits") "Pork", "e-commerce", "synthesis", "aquatic products"], 'sales': [random.randint (10,100) for _ in range (6)]}) print (df_origin) # in descending order of sales df_sorted = df_origin.sort_values (by='sales') Ascending=False) print (df_sorted) # Line chart x axis x_line_categories = [* range (7)] # Line chart y axis-downward cumulative frequency cum_percent = df_sorted ['sales'] .cumsum () / df_sorted [' sales'] .sum () * 100cum_percent = cum_percent.append (pd.Series ([0])) # add the starting frequency 0cum_percent = cum_percent.sort_values (ascending=True) print ( Df_sorted.categories.values.tolist () print (cum_percent.values.tolist ()) def pareto_bar ()-> Bar: line = (Line () .add _ xaxis (x_line_categories) .add _ yaxis (cumulative percentage) Cum_percent.values.tolist (), xaxis_index=1, yaxis_index=1, # use secondary y axis That is, extend_axis label_opts=opts.LabelOpts (is_show=False), is_smooth=True,)) bar = (Bar () .add _ xaxis (df_sorted.categories.values.tolist ()) .add _ yaxis ('sales', df_sorted.sales.values.tolist ()) in bar Category_gap=0) # .add _ yaxis ('percentage of total amount', cum_percent.values.tolist ()) .extend _ axis (xaxis=opts.AxisOpts (is_show=False, position='top')) .extend _ axis (yaxis=opts.AxisOpts (axistick_opts=opts.AxisTickOpts (is_inside=True), # scale facing inward axislabel_opts=opts.LabelOpts (formatter=' {value}%')) Position='right') .set _ series_opts (label_opts=opts.LabelOpts (is_show=True, font_size=14)) .set _ global_opts (title_opts=opts.TitleOpts (title=' Pareto example-sales\ n Make By tengyulong', subtitle=''), xaxis_opts=opts.AxisOpts (name=' item Type', type_='category') Yaxis_opts=opts.AxisOpts (axislabel_opts=opts.LabelOpts (formatter= "{value} pieces") bar.overlap (line) return barpareto_bar (). Render ('Pareto map .html') # or pareto_bar () .render_notebook ()

Render effect:

At this point, I believe you have a deeper understanding of "how to draw a Pareto map with Python". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Toto content percentage percentage Line Map sales Frequency Learning sales practicality depth interest scale scale Commodity coordinates Axis practicality actual Total Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Information Docker NVidia MariaDB