python之简易图表

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @data  : 2017/10/10 下午1:01
# @auth  : dyl
# @desc  :图表
import numpy as np
import matplotlib.pyplot as plt;
import matplotlib as mlb;
from pylab import *;

mpl.rcParams['font.sans-serif'] = ['SimHei'];  # 设置图表显示中文

'''
数据块
'''
datas = {"code": 2000, "sucinfo": "获取成功",
         "data": [{"id": 1, "data": '09.01', "money": "10"}, {"id": 2, "data": '09.02', "money": "56"},
                  {"id": 3, "data": '09.03', "money": "70"}, {"id": 4, "data": '09.04', "money": "16"},
                  {"id": 5, "data": '09.05', "money": "89"}, {"id": 6, "data": '09.06', "money": "68"}]};

i = 0;
datasLength = len(datas["data"]);  # 数据长度
# 定义x y轴数组长度 [n]*m n行m列的数组
xDatas = [1] * datasLength;
yDatas = [1] * datasLength;
# x y数组赋值从json数据中取出
for info in datas["data"]:
    xDatas[i] = info["data"];
    yDatas[i] = int(info["money"]);# 将字符类型的money转换为int类型
    i += 1;

'''
图表块
'''
# 创建绘图对象
plt.figure(figsize=(8, 4));

# 设置图标的标题
plt.title("订单收入")
# 设置X轴lable
plt.xlabel("date(日期)");
# 设置y轴lable
plt.ylabel("money(元)");
# 设置Y轴的范围
plt.ylim(0, 100);
# 设置X轴的范围
plt.xlim(0, len(xDatas) - 1);

# 开启网格
plt.grid();

# 通过调用plot函数在当前的绘图对象中进行绘图:lable图例 color线条颜色
plt.plot(xDatas, yDatas, label="收入(元)", color="red");
# 显示图例
plt.legend();

# 图表显示
plt.show();


你可能感兴趣的:(python之简易图表)