程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python Practical Basics] How to draw a pie chart to analyze commodity inventory

編輯:Python

Table of Contents

First, actual combatScene

Second, the main knowledge points

File read and write

Basic Grammar

String Handlingp>

File Generation

Data Construction

Three.

1. Create pythonDocument

2. Running results


First, the actual combat scene

Actual combat scenario: how to draw a pie chart to analyze product inventory

Second, the main knowledge points

  • File read and write

  • Basic syntax

  • String Handling

  • File Generation

  • Data Construction

Three,

Schedule now!

1. Create a python file

"""Author:Practical scenario: how to draw a pie chart to analyze commodity inventory"""# import system packagesimport platformfrom flask import Flask, render_templatefrom pyecharts import options as optsfrom pyecharts.charts import *from pyecharts.faker import Fakerprint("Hello,")print("Practical scenario: how to draw a pie chart to analyze product classification")web = Flask(__name__)# data buildx_data = ["shirt", "cardigan", "chiffon shirt", "pants", "high heels", "socks"]y_data = [1186, 1246, 1346, 1086, 1430, 1064]data = [[x_data[i], y_data[i]] for i in range(len(x_data))]def pie_charts() -> Pie():# instantiate the objectpie = Pie()# Use the Flask library to get the color directlypie.add("", data, color=Faker.rand_color())# Globally set title, labelpie.set_global_opts(title_opts=opts.TitleOpts(title="How to draw a pie chart to analyze product classification", subtitle=", keep learning!"),legend_opts=opts.LegendOpts(type_="scroll", orient="vertical", pos_top="20%", pos_left="0%"))return pie# get objectp = pie_charts()# Draw graphics and generate HTML filesp.render('./templates/pie_charts.html')# Add route display [email protected]('/')def index():return render_template('pie_charts.html')if __name__ == "__main__":# run the projectweb.run(debug=False)print("Python version", platform.python_version())

2. Results of operation

Hello,
Practical scenario: how to draw a pie chart to analyze product classification

* Serving Flask app 'py032' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000 (Press CTRL+C to quit)

Keep learning!

Let me introduce myself first. The editor graduated from Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Ali in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved