Example #1
0
def main():
    cs = {"01": "red", "05": "green", "09": "blue"}

    datas = contract.load()
    m = contract.filter_month(datas, cs)
    plt.ylabel("")
    ls = []

    ax = plt.gca()
    #指定X轴的以日期格式(带小时)显示
    ax.xaxis.set_major_formatter(mdates.DateFormatter('%y%m'))
    #X轴的间隔为天
    ax.xaxis.set_major_locator(mdates.MonthLocator())

    y_major_locator = MultipleLocator(200)
    ax.yaxis.set_major_locator(y_major_locator)

    date_2_price = {}

    for c in cs:
        if c not in m:
            continue
        d = m[c]
        ls.append(c)
        plt.plot(d["x"],
                 d["y"],
                 color=cs[c],
                 linestyle='-',
                 linewidth=1,
                 label="c")

        for i in d["x"]:
            if i in egg_price.date2price:
                date_2_price[i] = egg_price.date2price[i]

    dates = sorted(date_2_price)
    prices = []
    for k in dates:
        prices.append(date_2_price[k])

    ls.append("price")
    plt.plot(dates,
             prices,
             color="black",
             linestyle='-',
             linewidth=1,
             label="price")

    plt.legend(labels=ls, loc='best', shadow=True)
    plt.grid(axis="y", linestyle="--")
    plt.show()
Example #2
0
def main():
    month = input("please input month 01 ~ 12:  ");
    cs = {
        "jd14"+month:"gray",
        "jd15"+month:"pink",
        "jd16"+month:"green",
        "jd17"+month:"brown",
        "jd18"+month:"blue",
        "jd19"+month:"red",
        "jd20"+month:"black"
    }
    datas = contract.load()
    m = contract.filter(datas,cs,True)
    plt.xlabel("jdxx"+month)
    plt.ylabel("")
    ls = []
    
    ax = plt.gca()
    #指定X轴的以日期格式(带小时)显示
    ax.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
    #X轴的间隔为天
    ax.xaxis.set_major_locator(mdates.MonthLocator())
    
    y_major_locator=MultipleLocator(200)
    ax.yaxis.set_major_locator(y_major_locator)


    for c in cs:
        if c not in m:
            continue
        d = m[c]
        ls.append(c)
        plt.plot(d["x"],d["y"],color=cs[c],linestyle='-',linewidth = 1,label=c)
    plt.legend(labels = ls,loc = 'best',shadow = True)
    plt.grid(axis="y",linestyle="--")
    plt.show()
Example #3
0
def main():
    month1 = input("please input month1 01 ~ 12:  ")
    month2 = input("please input month2 01 ~ 12:  ")

    cs = [["jd14", "gray"], ["jd15", "pink"], ["jd16", "green"],
          ["jd17", "brown"], ["jd18", "blue"], ["jd19", "red"],
          ["jd20", "black"]]

    l = []
    name_list = []
    for i, val in enumerate(cs):
        a = val[0] + month1
        b = val[0] + month2
        if month2 < month1:
            if i >= len(cs) - 1:
                continue
            b = cs[i + 1][0] + month2
        l.append([a, b, a + " - " + b])
        name_list.append(a)
        name_list.append(b)

    datas = contract.load()
    m = contract.filter1(datas, name_list, False)

    ax = plt.gca()
    #指定X轴的以日期格式(带小时)显示
    ax.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d'))
    #X轴的间隔为小时
    ax.xaxis.set_major_locator(mdates.MonthLocator())

    y_major_locator = MultipleLocator(100)
    ax.yaxis.set_major_locator(y_major_locator)

    diff_l = []
    for pair in l:
        diff_x = []
        diff_y = []
        if pair[0] not in m or pair[1] not in m:
            continue
        ma = m[pair[0]]
        mb = m[pair[1]]
        year = int("20" + pair[0][2:4])
        for (date, v) in ma.items():
            if date not in mb:
                continue
            diff_y.append(v - mb[date])
            print(2019 + date.year - year, date.month, date.day)
            diff_x.append(
                datetime.date(2019 + date.year - year, date.month, date.day))

        diff_l.append([pair[2], diff_x, diff_y])

    plt.xlabel("jd price diff " + month1 + " " + month2)
    plt.ylabel("")
    ls = []
    labels = []
    for i, v in enumerate(diff_l):
        plt.plot(v[1],
                 v[2],
                 color=cs[i][1],
                 linestyle='-',
                 linewidth=1,
                 label=v[0])
        labels.append(v[0])

    plt.legend(labels=labels, loc='best', shadow=True)
    plt.grid(axis="y", linestyle="--")
    plt.show()
Example #4
0
# -*- coding: UTF-8 -*-
import os
import sys
import csv
current_dir = os.path.abspath(os.path.dirname(__file__))
sys.path.append(current_dir + '/..')

from data import contract
import datetime

cs = ["15", "16", "18"]
#cs.append("14")
#cs.append("17")
cs.append("19")

datas = contract.load()


def gen_diff(year, month1, month2):
    year = "jd" + year
    name_list = []
    a = year + month1
    b = year + month2
    name_list.append(a)
    name_list.append(b)

    m = contract.filter1(datas, name_list, False)

    diff_x = []
    diff_y = []
    if a not in m or b not in m:
Example #5
0
def main():
    year = input("please input year: ")
    cs = {
        "jd" + year + "01":
        "blue",
        #        "jd" + year + "02":"green",
        #        "jd" + year + "03":"pink",
        #        "jd" + year + "04":"brown",
        "jd" + year + "05":
        "green",
        #        "jd" + year + "06":"indigo",
        #        "jd" + year + "07":"plum",
        #        "jd" + year + "08":"purple",
        "jd" + year + "09":
        "red",
        #        "jd" + year + "10":"magenta",
        #        "jd" + year + "11":"gray",
        #        "jd" + year + "12":"teal"
    }
    datas = contract.load()
    m = contract.filter(datas, cs, False)
    plt.xlabel("jd20" + year)
    plt.ylabel("")
    ls = []

    ax = plt.gca()
    #指定X轴的以日期格式(带小时)显示
    ax.xaxis.set_major_formatter(mdates.DateFormatter('%y-%m'))
    #X轴的间隔为天
    ax.xaxis.set_major_locator(mdates.MonthLocator())

    y_major_locator = MultipleLocator(200)
    ax.yaxis.set_major_locator(y_major_locator)

    date_2_price = {}

    for c in cs:
        if c not in m:
            continue
        d = m[c]
        ls.append(c)
        plt.plot(d["x"],
                 d["y"],
                 color=cs[c],
                 linestyle='-',
                 linewidth=1,
                 label=c)

        for i in d["x"]:
            if i in egg_price.date2price:
                date_2_price[i] = egg_price.date2price[i]

    dates = sorted(date_2_price)
    prices = []
    for k in dates:
        prices.append(date_2_price[k])
    ls.append("price")
    plt.plot(dates,
             prices,
             color="black",
             linestyle='-',
             linewidth=1,
             label="price")

    plt.legend(labels=ls, loc='best', shadow=True)
    plt.grid(axis="y", linestyle="--")
    plt.show()