目录
一、实战场景
二、主要知识点
文件读写
基础语法
字符串处理
文件生成
数据构建
三、菜鸟实战
1、创建 python 文件
2、运行结果
实战场景:如何绘制箱形图分析电影数据
文件读写
基础语法
字符串处理
文件生成
数据构建
马上安排!
"""
Author: 菜鸟实战
实战场景: 如何绘制箱形图分析电影数据
"""
# 导入系统包
import platform
from flask import Flask, render_template
from pyecharts import options as opts
from pyecharts.charts import *
print("Hello,菜鸟实战")
print("实战场景: 如何绘制箱形图分析电影数据 \n")
web = Flask(__name__)
# 数据构建
x_index = ["剧情", "动作", "动画", "古装", "喜剧", "奇幻", "惊悚", "战争", "灾难", "爱情", "科幻", "魔幻"]
y_value1 = [[47923.0, 64988.0, 0.0, 80506.0, 0.0, 69628.0, 69960.0, 0.0, 104853.0, 539542.0, 157535.0],
[48249.0, 160800.0, 153735.0, 336616.0, 370696.0, 263476.0, 916503.0, 1010848.0, 1828313.0, 1835840.0,
875026.0],
[30916.0, 160800.0, 86419.0, 65659.0, 39472.0, 263476.0, 201318.0, 309825.0, 226052.0, 1835840.0, 152997.0],
[30916.0, 160800.0, 18648.0, 65659.0, 39472.0, 263476.0, 201318.0, 309825.0, 226052.0, 1835840.0, 152997.0],
[53837.0, 91838.0, 36093.0, 100303.0, 58872.0, 285139.0, 647028.0, 451028.0, 765806.0, 1063170.0, 454325.0],
[53837.0, 22874.0, 14934.0, 100303.0, 124699.0, 285139.0, 320647.0, 430395.0, 235246.0, 89988.0, 15283.0],
[20510.0, 22874.0, 14934.0, 18806.0, 124699.0, 41184.0, 320647.0, 430395.0, 235246.0, 89988.0, 15283.0],
[40329.0, 22874.0, 85732.0, 36994.0, 124699.0, 41184.0, 320647.0, 430395.0, 118754.0, 89988.0, 15283.0],
[44745.0, 22874.0, 85732.0, 36994.0, 124699.0, 41184.0, 62967.0, 430395.0, 118754.0, 89988.0, 15283.0],
[28092.0, 72729.0, 82385.0, 182193.0, 255790.0, 259325.0, 62967.0, 160092.0, 118754.0, 136152.0, 112725.0],
[51321.0, 213633.0, 148063.0, 225026.0, 258684.0, 563843.0, 344841.0, 82557.0, 179793.0, 139666.0,
465533.0],
[15524.0, 38100.0, 86684.0, 225026.0, 31579.0, 150820.0, 344841.0, 82557.0, 179793.0, 139666.0, 465533.0]]
def boxplot_charts() -> Boxplot():
# 实例化对象
boxplot = Boxplot()
boxplot.add_xaxis(x_index)
boxplot.add_yaxis("电影数据", y_value1)
# 全局置标题、标签
boxplot.set_global_opts(
title_opts=opts.TitleOpts(title="如何绘制箱形图分析电影数据", subtitle="菜鸟实战,坚持学习!"),
legend_opts=opts.LegendOpts(type_="scroll", pos_top="10%")
)
return boxplot
# 获取对象
p = boxplot_charts()
# 绘制图形,生成HTML文件的
p.render('./templates/boxplot_charts.html')
# 添加路由显示图表
@web.route('/')
def index():
return render_template('boxplot_charts.html')
if __name__ == "__main__":
# 运行项目
web.run(debug=False)
print("Python 版本", platform.python_version())
Hello,菜鸟实战
实战场景: 如何绘制箱形图分析电影数据* Serving Flask app 'py034' (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)
菜鸟实战,持续学习!