Python3.11
这是我写的第一个python项目,项目开始于2023年4月23日,中间断断续续的边学边开发,挺有纪念意义的。
CREATE SCHEMA `data_visualization` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'data_visualization'@'%' IDENTIFIED BY 'data_visualization';
GRANT ALL PRIVILEGES ON `data_visualization`.* TO 'data_visualization'@'%' WITH GRANT OPTION;
pip3 install -r requirements.txt
github上有一个收集常用字体的仓库,建议fork:https://github.com/Haixing-Hu/latex-chinese-fonts
在Linux系统中下载SimSun字体:
cd
wget https://github.com/Haixing-Hu/latex-chinese-fonts/raw/master/chinese/宋体/SimSun.ttc
mv SimSun.ttc SimSun.ttf
一定要在项目的虚环境中打开python-shell
shell> cd /root/yunzhu/dingwei-draw-image
shell> source venv/bin/activate
(venv)shell> python3
python>>> import matplotlib
python>>> matplotlib.get_data_path()
'/root/yunzhu/dingwei-draw-image/venv/lib/python3.10/site-packages/matplotlib/mpl-data'
cd /root/yunzhu/dingwei-draw-image/venv/lib/python3.10/site-packages/matplotlib/mpl-data/fonts/ttf
mv /root/SimSun.ttf .
一定要在项目的虚环境中打开python-shell
shell> cd /root/yunzhu/dingwei-draw-image
shell> source venv/bin/activate
(venv)shell> python3
python>>> import matplotlib
python>>> matplotlib.get_cachedir()
'/root/.cache/matplotlib'
rm -f /root/.cache/matplotlib/*
运行 main.py
GET http://127.0.0.1:5001/sysinfo/test
直接向接口提供绘图所需数据
POST http://127.0.0.1:5001/2d/data/submit
{
"data_source": {
"data_source_1": {
"data": ["1月", "2月", "3月", "4月", "5月", "6月"],
"comment": "月份"
},
"data_source_2": {
"data": [167, 253, 334, 577, 332, 690],
"comment": "维修工时"
},
"data_source_3": {
"data": [88, 78, 91, 99, 32, 22],
"comment": "平均工时"
},
"data_source_4": {
"data": [707, 432, 931, 801, 531, 327],
"comment": "维修物耗"
},
"data_source_5": {
"data": [91, 73, 103, 55, 91, 17],
"comment": "平均物耗"
}
}
}
响应
{
"code": 0,
"data": {
"A": {
"comment": "月份-维修工时",
"data_source_combination": ["data_source_1", "data_source_2"],
"support_plot_type": [1, 2, 3, 4, 5]
},
"B": {
"comment": "月份-平均工时",
"data_source_combination": ["data_source_1", "data_source_3"],
"support_plot_type": [1, 2, 3, 4, 5]
},
"C": {
"comment": "月份-维修物耗",
"data_source_combination": ["data_source_1", "data_source_4"],
"support_plot_type": [1, 2, 3, 4, 5]
},
"D": {
"comment": "月份-平均物耗",
"data_source_combination": ["data_source_1", "data_source_5"],
"support_plot_type": [1, 2, 3, 4, 5]
}
},
"msg": "30c55f6e-8a0d-4a53-b213-5e02088d0f83" <-----这个就是plot_key
}
POST http://127.0.0.1:5001/2d/chart/plotting
向绘图接口提交两个参数:
- plot_key: 提供数据源接口返回的plot_key
- plot_requirement_list: 绘图要求列表,形式如下
["A1", "A2"]
["A1"]
["A1", "B1", "C1"]
请求体
{
"plot_key": "30c55f6e-8a0d-4a53-b213-5e02088d0f83",
"plot_requirement": {
"figure1": {
"type": ["A1", "C1", "B2", "D2"],
"plot_title": "test figure"
},
"figure2": {
"type": ["A1", "C1", "B2", "D2"],
"plot_title": "test figure"
}
}
}
响应
{
"code": 200,
"data": {
"figure1": "10.211.55.10:9001/py-data-visualization/fa1f165b-cdf6-4d27-b1f5-28da3a9d7907.png",
"figure2": "10.211.55.10:9001/py-data-visualization/fa1f165b-cdf6-4d27-b1f5-28da3a9d7907.png"
},
"msg": "绘图需求校验通过,绘图结果请查看data"
}