Skip to content

xavier72bit/data_visualization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

环境要求

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

SimSun字体安装(Linux)

1. 下载SimSun字体文件

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

2. 将字体文件移动到matplotlib的字体目录中

2.1 先获取matplotlib的mpl-data目录的位置

一定要在项目的虚环境中打开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'

2.2 移动字体文件到matplotlib的字体目录中

cd /root/yunzhu/dingwei-draw-image/venv/lib/python3.10/site-packages/matplotlib/mpl-data/fonts/ttf
mv /root/SimSun.ttf .

3. 清理matplotlib的缓存

3.1 先获取matplotlib缓存目录

一定要在项目的虚环境中打开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'

3.2 删除缓存目录下的所有文件

rm -f /root/.cache/matplotlib/*

项目启动

运行 main.py

接口使用说明

1. 测试服务可用

GET http://127.0.0.1:5001/sysinfo/test

2. 提供数据源

直接向接口提供绘图所需数据

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
}

3. 绘图

POST http://127.0.0.1:5001/2d/chart/plotting

向绘图接口提交两个参数:

  1. plot_key: 提供数据源接口返回的plot_key
  2. 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"
}

效果

About

Python数据可视化服务

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages