1 Star 0 Fork 0

dingqiao/Flask_CaseCreate

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ChartTrends.py 2.07 KB
一键复制 编辑 原始数据 按行查看 历史
dingqiao 提交于 2024-09-15 06:59 . update
from flask import Flask, send_file, render_template
from DataAnalysis.matplotIMG import Drawer
app = Flask(__name__)
@app.route('/plot')
def plot_image():
# 定义时间点和对应的数据
time_points = ['00:00:00', '01:00:00', '02:00:00', '03:00:00', '04:00:00', '05:00:00',
'06:00:00', '07:00:00', '08:00:00', '09:00:00', '10:00:00', '11:00:00', '00:00:00', '01:00:00',
'02:00:00', '03:00:00', '04:00:00', '05:00:00',
'06:00:00', '07:00:00', '08:00:00', '09:00:00', '10:00:00', '11:00:00']
data = [5, 10, 8, 4, 25, 12, 6, 22, 17, 23, 9, 55, 5, 10, 8, 4, 25, 12, 6, 22, 17, 23, 9, 55]
#
# # 创建图形和轴
# fig, ax = plt.subplots(figsize=(10, 6))
#
# # 计算时间点的中点位置
# time_positions = np.arange(len(time_points)) + 0.5
#
# # 绘制折线图,数据点落在时间区间的中点位置
# ax.plot(time_positions, data, marker='o')
#
# # 设置图形标题和轴标签
# ax.set_title('Interval Line Plot from 00:00 to 12:00')
# ax.set_xlabel('Time Intervals')
# ax.set_ylabel('Data')
#
# # # 设置 x 轴刻度和标签
# # ax.set_xticks(np.arange(len(time_points)))
# # ax.set_xticklabels(time_points, rotation=45)
# num_ticks = round(len(time_points) // 8)
# # num_ticks = int(num_ticks)
# # 设置 x 轴刻度和标签,每隔 2 个时间点显示一个标签
# ax.set_xticks(time_positions[::num_ticks])
# ax.set_xticklabels(time_points[::num_ticks], rotation=0)
# max_value = ((max(data) + 10) // 10 + 1) * 10
# ax.set_ylim(0, max_value)
# # 设置每个点的数字显示
# for i in range(len(time_points)):
# ax.text(i + 0.5, data[i] + 0.5, str(data[i]), ha='center', va='bottom')
# 将图表保存到内存中
buf = Drawer.draw_line(time_points, data)
# 返回图表作为响应
return send_file(buf, mimetype='image/png')
@app.route('/')
def index():
return render_template('IMGDemo.html')
if __name__ == '__main__':
app.run(debug=True, host='127.0.0.1', port=5000)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/dingqiao1638105266/flask_-case-create.git
[email protected]:dingqiao1638105266/flask_-case-create.git
dingqiao1638105266
flask_-case-create
Flask_CaseCreate
master

搜索帮助