Ejemplo n.º 1
0
Archivo: rt.py Proyecto: vito-jwt/rt
def now_to_mins_1_number():
    snow=datetime.datetime.now().strftime('%Y-%m-%d %H')
    snow1=datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
    v=date2num(datetime.datetime.strptime(snow,'%Y-%m-%d %H'))
    tnow=date2num(datetime.datetime.strptime(snow1,'%Y-%m-%d %H:%M'))-v
    x=math.floor(tnow*1440)/1440
    return x+v
Ejemplo n.º 2
0
Archivo: rt.py Proyecto: vito-jwt/rt
def now_to_hours_4_number():
    snow=datetime.datetime.now().strftime('%Y-%m-%d')
    snow1=datetime.datetime.now().strftime('%Y-%m-%d %H')
    
    v=date2num(datetime.datetime.strptime(snow,'%Y-%m-%d'))
    tnow=date2num(datetime.datetime.strptime(snow1,'%Y-%m-%d %H'))-v
    x=math.floor(tnow*6)/6
    easylog.info("flag_before: %s,%s,",snow1,x)
    return x+v
Ejemplo n.º 3
0
    def generate_xticks(self, all_days, monthsamp=1):
        """
        generate xticks

        all_days: array of times (days since 01-0-0)
        """

        dd = pl.num2date(all_days)
        xticks = []
        xticklabels = []
        last_month = dd[0].month
        last_year = dd[0].year

        xticks.append(all_days[0])
        strmon = get_month_string(dd[0].month)
        if self.yearonly:
            xticklabels.append(str(dd[0].year))
        else:
            xticklabels.append(strmon + '\n' + str(dd[0].year))

        for d in dd:
            if (d.month != last_month) | (d.year != last_year):
                xticks.append(pl.date2num(d))  # save tick location
                mstr = get_month_string(d.month)
                if self.yearonly:
                    xticklabels.append(str(d.year))
                else:
                    if (d.year != last_year):
                        xticklabels.append(mstr + '\n' + str(d.year))
                    else:
                        xticklabels.append(mstr + '\n' + '')
                last_month = d.month
                last_year = d.year

        if self.transpose:
            scal = self.rescaley
        else:
            scal = self.rescalex
        xticks = np.asarray(xticks)

        # /// remap to image coordinates
        ny, nx = np.shape(self.hov)
        w = (xticks - pl.date2num(self.t_min)) / (
            pl.date2num(self.t_max) - pl.date2num(self.t_min)
        )  # weights for positions on x-axis

        xticks = w * nx * scal
        xticks = list(xticks)

        # here we have monthly ticks which we can now subsample
        xticks = xticks[::monthsamp]
        xticklabels = xticklabels[::monthsamp]

        self.x_major_locator = pl.FixedLocator(xticks)
        self.x_major_formatter = pl.FixedFormatter(xticklabels)
Ejemplo n.º 4
0
    def generate_xticks(self, all_days, monthsamp=1):
        """
        generate xticks

        all_days: array of times (days since 01-0-0)
        """

        dd = pl.num2date(all_days)
        xticks = []
        xticklabels = []
        last_month = dd[0].month
        last_year = dd[0].year

        xticks.append(all_days[0])
        strmon = get_month_string(dd[0].month)
        if self.yearonly:
            xticklabels.append(str(dd[0].year))
        else:
            xticklabels.append(strmon + '\n' + str(dd[0].year))

        for d in dd:
            if (d.month != last_month) | (d.year != last_year):
                xticks.append(pl.date2num(d))  # save tick location
                mstr = get_month_string(d.month)
                if self.yearonly:
                    xticklabels.append(str(d.year))
                else:
                    if (d.year != last_year):
                        xticklabels.append(mstr + '\n' + str(d.year))
                    else:
                        xticklabels.append(mstr + '\n' + '')
                last_month = d.month
                last_year = d.year

        if self.transpose:
            scal = self.rescaley
        else:
            scal = self.rescalex
        xticks = np.asarray(xticks)

        # /// remap to image coordinates
        ny, nx = np.shape(self.hov)
        w = (xticks - pl.date2num(self.t_min)) / (pl.date2num(self.t_max)
                                                  - pl.date2num(self.t_min))  # weights for positions on x-axis

        xticks = w * nx * scal
        xticks = list(xticks)

        # here we have monthly ticks which we can now subsample
        xticks = xticks[::monthsamp]
        xticklabels = xticklabels[::monthsamp]

        self.x_major_locator = pl.FixedLocator(xticks)
        self.x_major_formatter = pl.FixedFormatter(xticklabels)
Ejemplo n.º 5
0
def date_to_num(dates, timecard):
    num_time = []
    if timecard == 'D':
        for date in dates:
            date_time = datetime.datetime.strptime(date, '%Y-%m-%d')
            num_date = date2num(date_time)
            num_time.append(num_date)
    elif timecard == '30':
        for date in dates:
            date_time = datetime.datetime.strptime(date, '%Y-%m-%d %H:%M')
            num_date = date2num(date_time)
            num_time.append(num_date)
    return num_time
Ejemplo n.º 6
0
def InputArgs():
    parser = argparse.ArgumentParser(description="show example")

    # parser.add_argument('hs300_stocks', default=['000300.sh'], nargs='*')
    parser.add_argument("-a", "--append", default=1, help="append")
    parser.add_argument("-c", "--count", default=20, help="stock count")
    parser.add_argument("-e", "--end_date", default='', help="end date")
    parser.add_argument("-f",
                        "--record_file",
                        default='hs300',
                        help="record file")
    parser.add_argument("-l", "--stop_loss", default=3, help="stop loss")
    parser.add_argument("-p",
                        "--data_path",
                        default='./data-qfq-13',
                        help="stock data path")
    parser.add_argument("-s",
                        "--start_date",
                        default='20140101',
                        help="start date")
    parser.add_argument("-S",
                        "--strong_cycle",
                        default=20,
                        help="strong cycle")
    parser.add_argument("-u", "--loss_unit", default=0.01, help="loss unit")

    ARGS = parser.parse_args()
    global cmdline

    if ARGS.start_date:
        _date = dt.datetime.strptime(str(ARGS.start_date), '%Y%m%d')
        cmdline['start_date'] = date2num(_date)
    if ARGS.end_date:
        _date = dt.datetime.strptime(str(ARGS.end_date), '%Y%m%d')
        cmdline['end_date'] = date2num(_date)

    if ARGS.data_path:
        cmdline['data_path'] = ARGS.data_path
    if ARGS.record_file:
        cmdline['record_file'] = ARGS.record_file
    if ARGS.count:
        cmdline['stock_count'] = int(ARGS.count)

    if ARGS.loss_unit:
        cmdline['loss_unit'] = float(ARGS.loss_unit)
    if ARGS.append:
        cmdline['append'] = int(ARGS.append)
    if ARGS.stop_loss:
        cmdline['stop_loss'] = int(ARGS.stop_loss)
    if ARGS.strong_cycle:
        cmdline['strong_cycle'] = int(ARGS.strong_cycle)
Ejemplo n.º 7
0
def loadData(draw=False, count=100):
    if (draw):
        data = []
        for i in range(1, 5):
            with open(data_root_path + "/stock_data_" + str(i) + ".data") as f:
                while (True):
                    line_str = f.readline().replace("\n", "").split(" ")
                    if (len(line_str) != 6):
                        break
                    results = list(map(float, line_str))
                    results[0] = (date2num(parse(str(results[0]))))

                    data.append(tuple(results))
        pass
    else:
        data = []
        for i in range(1, 5):
            with open(data_root_path + "/stock_data_" + str(i) + ".data") as f:
                while (True):
                    line_str = f.readline().replace("\n", "").split(" ")
                    if (len(line_str) != 6):
                        break
                    results = list(map(float, line_str))
                    #去除date
                    results.pop(0)
                    data.append(results)

        pass
    return data
Ejemplo n.º 8
0
def date_to_num(dates):
    ''' Function to convert tushare 'date' string to matplotlib datenum
    
    Input
    =====
    dates: ndarray of tushare 'date' strings. Eg. ['2013-01-31', ...]
    
    Output
    ======
    Return: list of float datetime value compatible to matplotlib: floating point 
            numbers which represent time in days since 0001-01-01 UTC, plus 1. 
            For example, 0001-01-01, 06:00 is 1.25, not 0.25.
    
    Example
    =======
        stock_data['mpl.date'] = date_to_num(stock_data['date'].values)

    '''
    num_time = []
    for date in dates:
        date_time = datetime.datetime.strptime(date, '%Y-%m-%d')
        num_date = date2num(date_time)
        '''
            matplotlib.dates.date2num(d)
                Converts datetime objects to Matplotlib dates
        '''
        num_time.append(num_date)
    return num_time
Ejemplo n.º 9
0
 def plot_chart(self, data, n, ticker):
     
     ''' plot the information for one stock (inclding: Moving Average, MACD, RSI, Volume)
         param data: datafram for the stock
         param n: n index before the end date
         param ticker: single stock ticker
     '''
 
     data["macd"], data["macd_signal"], data["macd_hist"] = talib.MACD(data['Adj Close'])
     
     # Get MA10 and MA30
     data["ma10"] = talib.MA(data["Adj Close"], timeperiod=10)
     data["ma30"] = talib.MA(data["Adj Close"], timeperiod=30)
     
     # Get RSI
     data["rsi"] = talib.RSI(data["Adj Close"])
     # Filter number of observations to plot
     data = data.iloc[-n:]
     
     # Create figure and set axes for subplots
     fig = plt.figure()
     fig.set_size_inches((20, 16))
     ax_candle = fig.add_axes((0, 0.72, 1, 0.32))
     ax_macd = fig.add_axes((0, 0.48, 1, 0.2), sharex=ax_candle)
     ax_rsi = fig.add_axes((0, 0.24, 1, 0.2), sharex=ax_candle)
     ax_vol = fig.add_axes((0, 0, 1, 0.2), sharex=ax_candle)
     
     # Format x-axis ticks as dates
     ax_candle.xaxis_date()
     
     # Get nested list of date, open, high, low and close prices
     ohlc = []
     for date, row in data.iterrows():
         openp, highp, lowp, closep = row[:4]
         ohlc.append([date2num(date), openp, highp, lowp, closep])
     # Plot candlestick chart
     ax_candle.plot(data.index, data["ma10"], label="MA10")
     ax_candle.plot(data.index, data["ma30"], label="MA30")
     # candlestick_ohlc(ax_candle, ohlc, colorup="g", colordown="r", width=0.8)
     # ax_candle.legend()
     ax_candle.plot(data.index, data['Adj Close'], label = 'Price')
     # Plot MACD
     ax_macd.plot(data.index, data["macd"], label="macd")
     ax_macd.bar(data.index, data["macd_hist"] * 3, label="hist")
     ax_macd.plot(data.index, data["macd_signal"], label="signal")
     ax_macd.legend()
     # Plot RSI
     # Above 70% = overbought, below 30% = oversold
     ax_rsi.set_ylabel("(%)")
     ax_rsi.plot(data.index, [70] * len(data.index), label="overbought")
     ax_rsi.plot(data.index, [30] * len(data.index), label="oversold")
     ax_rsi.plot(data.index, data["rsi"], label="rsi")
     ax_rsi.legend()
     # Show volume in millions
     ax_vol.bar(data.index, data["Volume"] / 1000000)
     ax_vol.set_ylabel("(Million)")
    
     # Save the chart as PNG
     fig.savefig("charts/" + ticker + ".png", bbox_inches="tight")
     plt.show()  
Ejemplo n.º 10
0
    def query_index_daily(self, code):

        df = IndustryData().get_index_daily(code)
        print( df.head(10) )

        df['date']=df['date'].apply( lambda x:date2num(x))
        ohlc=df[['date','open','high','low','close']]
        ohlc.rename(columns={'date':'t'}, inplace=True)
        ohlc['open']=ohlc['open'].apply( lambda  x:float(x))
        ohlc['high']=ohlc['high'].apply( lambda  x:float(x))
        ohlc['low']=ohlc['low'].apply( lambda  x:float(x))
        ohlc['close']=ohlc['close'].apply( lambda  x:float(x))
        print( ohlc.head(10))
        self.f_plot.clear()
        self.f_plot.xaxis_date()
        self.f_plot.autoscale_view()
        plt.xticks(rotation=45)
        plt.yticks()
        plt.title(" {0}".format(code))
        plt.xlabel("date")
        plt.ylabel("price")
        print( ohlc.head(10))
        print( ohlc.values)
        mpf.candlestick_ohlc(self.f_plot, ohlc.values, colorup='red', colordown='green')
        plt.legend(loc='best', shadow=True)
        plt.grid()
        self.canvs.draw()
Ejemplo n.º 11
0
def drawKFig(quote_code, start_date, end_date):
    plt.rcParams['font.sans-serif'] = ['SimHei']
    plt.rcParams['axes.unicode_minus'] = False
    
    # 瀵箃ushare鑾峰彇鍒扮殑鏁版嵁杞崲鎴恈andlestick_ohlc()鏂规硶鍙鍙栫殑鏍煎紡
    data_list = []
    
    hist_data = ts.get_hist_data(quote_code, start=start_date, end=end_date)  # 涓�娆℃�ц幏鍙栧叏閮ㄦ棩k绾挎暟鎹�
    for date, row in hist_data.iterrows():
        # 灏嗘椂闂磋浆鎹负鏁板瓧
        date_time = datetime.datetime.strptime(date, '%Y-%m-%d')
        t = date2num(date_time)
        open, high, close, low = row[:4]
        datas = (t, open, high, low, close)
        print(datas)
        data_list.append(datas)
     
    # 鍒涘缓瀛愬浘
    fig, ax = plt.subplots()
    fig.subplots_adjust(bottom=0.2)
    
    # 璁剧疆X杞村埢搴︿负鏃ユ湡鏃堕棿
    ax.xaxis_date()
    plt.xticks(rotation=45)
    plt.yticks()
    plt.title(u"鑲$エ浠g爜锛�" + quote_code)
    plt.xlabel(u"鏃堕棿")
    plt.ylabel(u"鑲′环锛堝厓锛�")
    mpf.candlestick_ohlc(ax, data_list, width=0.9, colorup='red', colordown='green')
    ax.autoscale_view()
    plt.grid()
    plt.show()
    pass
Ejemplo n.º 12
0
def date_to_num(dates):
    num_time = []
    for date in dates:
        date_time = datetime.datetime.strptime(date, '%Y-%m-%d')
        num_date = date2num(date_time)
        num_time.append(num_date)
    return num_time
Ejemplo n.º 13
0
def draw_l1_fcbs_(fEPs, sSatLst, plt):

    xtm = []
    for ss in sSatLst:
        xp=[]
        yp=[]

        for fE0 in fEPs:
            for fb in fE0.inf_fbs:
                if fb.id == ss:
                    xp.append(fE0.tm)
                    yp.append(fb.val)

        if len(yp)<3:
            continue

        plt.plot(xp, yp, '.', label=ss)
        xtm.append(xp[0])
        xtm.append(xp[-1])


    if len(xtm)>3:
        tmflt = date2num(xtm)
        plt.xlim(tmflt.min() - 0.000001, tmflt.max() + 0.000001)
    plt.grid(True)
Ejemplo n.º 14
0
def sample_513():
    """
    5.1.3 k线图的绘制
    :return:
    """
    # import matplotlib.finance as mpf
    import mpl_finance as mpf
    from matplotlib.pylab import date2num

    __colorup__ = "red"
    __colordown__ = "green"
    # 为了示例清晰,只拿出前30天的交易数据绘制蜡烛图,
    tsla_part_df = tsla_df[:30]
    fig, ax = plt.subplots(figsize=(14, 7))
    qutotes = []

    for index, (d, o, c, h, l) in enumerate(
            zip(tsla_part_df.index, tsla_part_df.open, tsla_part_df.close,
                tsla_part_df.high, tsla_part_df.low)):
        # 蜡烛图的日期要使用matplotlib.finance.date2num进行转换为特有的数字值
        d = date2num(d)
        # 日期,开盘,收盘,最高,最低组成tuple对象val
        val = (d, o, c, h, l)
        # 加val加入qutotes
        qutotes.append(val)
    # 使用mpf.candlestick_ochl进行蜡烛绘制,ochl代表:open,close,high,low
    mpf.candlestick_ochl(ax,
                         qutotes,
                         width=0.6,
                         colorup=__colorup__,
                         colordown=__colordown__)
    ax.autoscale_view()
    ax.xaxis_date()
    plt.show()
Ejemplo n.º 15
0
def printKline(stock):
    re = getFullQuoteByStock(stock)
    re = re.set_index('date')
    #re.index = pd.to_datetime(re.index)
    data_list = []
    re = re.drop('index', 1)
    for dates, row in re.iterrows():
        date_time = datetime.datetime.strptime(dates, '%Y-%m-%d')
        t = date2num(date_time)
        open, high, low, close = row[:4]
        datas = (t, open, high, low, close)
        data_list.append(datas)

    fig, ax = plt.subplots()
    fig.subplots_adjust(bottom=0.2)
    ax.xaxis_date()
    plt.xticks(rotation=45)
    plt.yticks()
    plt.title("STOCK:" + stock)
    plt.xlabel("time")
    plt.ylabel("price")
    mpf.candlestick(ax, data_list, width=1.5, colorup='r', colordown='green')
    plt.grid()
    plt.show()
    plt.savefig('/Users/momo/Programs/python/result/' + stock + '.png')
Ejemplo n.º 16
0
def printKlines(stocks, savepath, fileName):
    stockNum = len(stocks)
    fig = plt.figure()
    fig.set_size_inches(18.5, 18.5)
    i = 1
    for stock in stocks:

        re = getFullQuoteByStock(stock)
        re = re.set_index('date')
        #re.index = pd.to_datetime(re.index)
        data_list = []
        re = re.drop('index', 1)
        for dates, row in re.iterrows():
            date_time = datetime.datetime.strptime(dates, '%Y-%m-%d')
            t = date2num(date_time)
            open, high, low, close = row[:4]
            datas = (t, open, high, low, close)
            data_list.append(datas)

        ax = fig.add_subplot(stockNum, 1, i)
        #fig.subplots_adjust(bottom=0.2)
        ax.xaxis_date()
        #plt.xticks(rotation=45)
        plt.xticks()
        plt.yticks()
        plt.title("STOCK:" + stock)
        plt.xlabel("time")
        plt.ylabel("price")
        mpf.candlestick(ax, data_list, width=1, colorup='r', colordown='green')
        plt.grid()
        i = i + 1
    #plt.show()
    plt.savefig(savepath + fileName, dpi=100)
Ejemplo n.º 17
0
def eg9_10():
    """
    9.10 动手实践:绘制股价分布直方图
        我们来绘制从雅虎财经频道下载的股价数据的分布直方图。
    """
    # (1) 下载一年以来的数据:
    today = date.today()
    start = date(today.year - 1, today.month, today.day)

    # (2) 上一步得到的股价数据存储在Python列表中。将其转化为NumPy数组并提取出收盘价数据:
    df_stock = pd.read_csv('output/AAPL.csv', header=0, index_col=None)
    quotes = []
    for i in range(df_stock.shape[0]):  # 遍历每行,shape为dataframe大小(x,y),表示x行y列
        if i == 0:
            # 将交易日期日期转为数字
            date_num = date2num(datetime.strptime(df_stock.ix[[i]].values[0][0], '%Y-%m-%d'))  # 1表示第一列,为交易日
            date_plt = date_num
        else:
            date_plt = date_num + i  # 由于csv文件中日期为升序排序,这里为加号
        open = df_stock.ix[[i]].values[0][1]  # 开盘价: i行第2列
        close = df_stock.ix[[i]].values[0][2]  # 收盘价:i行第3列
        high = df_stock.ix[[i]].values[0][3]  # 最高价:i行第4列
        low = df_stock.ix[[i]].values[0][4]  # 最低价:i行第5列
        datas = (date_plt, open, close, high, low)
        quotes.append(datas)
    quotes = np.array(quotes)
    close = quotes.T[4]
    print close

    # (3) 指定合理数量的柱形,绘制分布直方图:
    print len(close)
    print np.sqrt(len(close))
    plt.hist(close, int(np.sqrt(len(close))))    # 返回len(close)的平方根,保留为整数
    plt.show()
Ejemplo n.º 18
0
def get_monthly_abstract_price(company):
    print("Company: ", company)   
    # get data from iexfinance 
    goal = Stock(company, token=Token)
    mon_pri_dics = goal.get_historical_prices() 
    # create a new list
    mon_pri_data = []
    # change the data into the form that mpf.candlestick_ochl function can read
    for dic in mon_pri_dics:
        # get date open high low close volume
        list(dic.values())[0:6]
        # change date into number
        t = date2num(datetime.datetime.strptime(list(dic.values())[0], '%Y-%m-%d'))
        # change sequence into the form that mpf.candlestick_ochl function can read
        ope, close, high, low, vol = list(dic.values())[1:6]
#         print(ope, close, high, low, vol)
         # change the data into the form that mpf.candlestick_ochl function can read
        data = [t, ope, close, high, low, vol]
        mon_pri_data.append(data)
    
    # draw the figure
    # set ax as the style of figure   
    fig, ax = plt.subplots(figsize = (15,3.5))
    plt.rcParams['savefig.dpi'] = 500
    # set parameters of plot_day_summary_oclh: ax = ax sample; mon_pri_data = data color up = close > open; color down = open > close
    
    plot_day_summary_oclh(ax, mon_pri_data, colorup = 'r', colordown = 'g')
    ax.set_title('Candlestick Abstract Chart of' + ' ' + company)
    plt.grid(True)
    # set price label
    plt.ylabel('Price')
    # set x axis as date
    ax.xaxis_date ()
    plt.show()
    return plt.savefig('monthabstractprice.png')
Ejemplo n.º 19
0
    def initial_figure(self):

        DB = MongoDB.MongoDBData()
        df = DB.datafromMongoDB(self.dbname, self.tick)
        df = df.loc[self.start_date:self.end_date, ['open', 'high', 'low', 'close']]

        Data_list = []
        for date, row in df.iterrows():
            Date = date2num(dt.datetime.strptime(date, "%Y-%m-%d"))
            Open, High, Low, Close = row[:4]
            Data = (Date, Open, High, Low, Close)
            Data_list.append(Data)

        self.axes.xaxis_date()
        # self.axes.plot(df['open'], df['close'])
        # fig, ax = plt.subplots()
        # fig.subplots_adjust(bottom=0.2)
        # 设置X轴刻度为日期时间
        # ax.xaxis_date()
        # plt.xticks(rotation=45)
        # plt.yticks()
        # plt.title("股票代码:601558两年K线图")
        # plt.xlabel("时间")
        # plt.ylabel("股价(元)")
        plt.tight_layout()
        mpf.candlestick_ohlc(self.axes, Data_list, width=1.5, colorup='r', colordown='green')
def get_candles_data(url,contractSize):
    print(url)
    response = requests.get(url)
    data_arr = response.text.replace("[[",'').replace("]]",'').replace("\"","").split("],[")
    close = []
    high = []
    low = []
    tradeTime = []
    for item_str in reversed(data_arr):
        item = item_str.split(",")
        sdatetime_num = date2num(datetime.strptime(item[0].replace("T",' ').replace('.000Z',''),'%Y-%m-%d'))
        # datas = (sdatetime_num,float(item[1]),float(item[2]),float(item[3]),float(item[4])) # 按照 candlestick_ohlc 要求的数据结构准备数据
        # quotes.append(datas)
        tradeTime.append(sdatetime_num)
        high.append(float(item[2])*contractSize)
        low.append(float(item[3])*contractSize)
        close.append(float(item[4])*contractSize)
    dt_dict = {'tradeTime':tradeTime,
               'high':high,
               'low':low,
               'close':close}
    data_df = DataFrame(dt_dict)
    atr = ta.ATR(data_df['high'],data_df['low'],data_df['close'],timeperiod=14)
    data_df["atr"]=atr
    data_df["atrRatio"]=data_df["atr"]/data_df['close']
    atrRatio = data_df["atrRatio"]
    if len(data_df["atrRatio"])>300:
        atrRatio = data_df["atrRatio"][len(data_df["atrRatio"])-300:len(data_df["atrRatio"])-1]
    # print(atrRatio)
    return list(atrRatio)
Ejemplo n.º 21
0
def drawK(k_dict):

    k_dict = dict(sorted(k_dict.items()))
    quotes = list()
    for k, v in k_dict.items():
        sdate_num = date2num(datetime.datetime.strptime(
            k, '%Y-%m-%d'))  # 日期需要特定形式,这里进行转换
        sopen = v[0]
        sclose = v[-1]
        shigh = max(v)
        slow = min(v)
        datas = (sdate_num, sopen, shigh, slow, sclose)
        quotes.append(datas)

    fig, ax = plt.subplots(facecolor=(1, 0.6, 0.6), figsize=(12, 8))
    fig.subplots_adjust(bottom=0.1)
    ax.xaxis_date()
    plt.xticks(rotation=45)  # 日期显示的旋转角度
    plt.title('K')
    plt.xlabel('Time')
    plt.ylabel('Money')
    mpf.candlestick_ohlc(ax, quotes, width=0.7, colorup='r',
                         colordown='green')  # 上涨为红色K线,下跌为绿色,K线宽度为0.7
    plt.grid(True)
    plt.show()
    print("Done.")
Ejemplo n.º 22
0
    def candle_draw(self, id='', df=None):
        wx = lg.get_handle()
        if df is None:
            wx.info("[mp_painter][candle_draw] dataframe is Empty, return")
            return

        fake_date_arr = ['20000101']
        fake_date = datetime.strptime('20000101', '%Y%m%d')
        i = 1
        while i < len(df):
            fake_date += timedelta(days=1)
            fake_date_arr.append(fake_date.strftime('%Y%m%d'))
            i += 1

        # 日期处理为时间戳
        real_trade_date = df['trade_date'].copy().tolist()
        df['trade_date'] = fake_date_arr
        df.trade_date = df.trade_date.apply(
            lambda x: date2num(datetime.strptime(x, "%Y%m%d")))

        # Tushare 返回的数据 按日期倒序,按日期升序后,需要把倒序的index先删掉,再重新生成升序的 index
        # 用 index 填充 日期列,当做日期使用
        # df.reset_index(drop=False, inplace=True)
        # df.drop('index', axis=1, inplace=True)
        # df.reset_index(drop=False, inplace=True)
        # df.drop('trade_date', axis=1, inplace=True)
        # df.index = df.index.apply(lambda x: date2num(x))

        candle_array = df.values
        # 创建一个子图
        fig, ax = plt.subplots(facecolor=(0.5, 0.5, 0.5))
        fig.subplots_adjust(bottom=0.1)
        # 设置X轴刻度为日期时间
        ax.xaxis_date()
        ax.autoscale_view()

        candlestick_ohlc(ax,
                         candle_array,
                         colordown='#53c156',
                         colorup='#ff1717',
                         width=0.3,
                         alpha=1)
        # ax.xaxis.set_major_locator(ticker.MultipleLocator(6))
        # ax.set_xticks(range(len(real_trade_date)))
        # ax.set_xticklabels(real_trade_date)
        formatter = MyFormatter(real_trade_date)
        ax.xaxis.set_major_formatter(formatter)

        plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
        plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号

        # X轴刻度文字倾斜45度
        # plt.xticks( rotation=45)
        plt.grid(True)
        plt.title("回测结果:[" + id + "] K线图")
        plt.xlabel("日期")
        plt.ylabel("价格(元)")
        # candlestick_ochl(ax, candle_array, colordown='#53c156', colorup='#ff1717', width=0.3, alpha=1)
        plt.show()
Ejemplo n.º 23
0
 def drawAbsRBacktest(self,portReturn,portReturn1,dailyDate,path,name):
     pylab.clf()
     pylab.plot_date(pylab.date2num(dailyDate),portReturn,'r',linewidth=0.8,linestyle='-') 
     pylab.plot_date(pylab.date2num(dailyDate),portReturn1,'b',linewidth=0.8,linestyle='-') 
     xtext = pylab.xlabel('Out-Of-Sample Date')  
     ytext = pylab.ylabel('Cumulative Return')  
     ttext = pylab.title('Portfolio Return Vs Benchmark Return') 
     pylab.grid(True)
     pylab.setp(ttext, size='large', color='r')   
     pylab.setp(xtext, size='large', weight='bold', color='g')  
     pylab.setp(ytext, size='large', weight='light', color='b')  
     
     yearFormat=matDate.DateFormatter('%Y%m%d')
     ax=pylab.gca()
     ax.xaxis.set_major_formatter(yearFormat)        
     
     pylab.savefig('%s%sAbsRbacktest.png'%(path,name))    
Ejemplo n.º 24
0
def date_to_num(dates):
    """将日期转换为matplotlib可以识别的日期格式"""
    num_time = []
    for date in dates:
        date_time = datetime.datetime.strptime(date, "%Y-%m-%d")
        num_date = date2num(date_time)
        num_time.append(num_date)
    return num_time
Ejemplo n.º 25
0
 def float_date(_date):
     if isinstance(_date, np.int64):
         _date = str(_date)
     if isinstance(_date, str):
         _date = dt.datetime.strptime(_date, '%Y%m%d')
     if isinstance(_date, dt.datetime):
         _date = date2num(_date)
     return _date
 def plot_figure(self):
     item = self.item
     mpl_dates = date2num(item.index)
     plt.figure(figsize=(8, 4))
     plt.scatter(item['GLD'], item['SLV'], c=mpl_dates, marker='o', s=8)
     plt.grid(True)
     plt.xlabel('GLD')
     plt.ylabel('SLV')
     plt.colorbar(ticks=DayLocator(interval=250), format=DateFormatter('%d %b %y'))
Ejemplo n.º 27
0
def filllist(res):
    data_list = []
    for block in res['data']:
        dt = datetime.datetime.utcfromtimestamp(
            block['id']) + datetime.timedelta(hours=8)
        # mpf库中要求的顺序是:时间、开盘价、最高价、最低价、收盘价
        data_list.append((date2num(dt), block['open'], block['high'],
                          block['low'], block['close']))
    return data_list
Ejemplo n.º 28
0
 def float_date(_date):
     if isinstance(_date, numpy.int64) or isinstance(_date, int):
         _date = str(_date)
     if isinstance(_date, str):
         _date = datetime.datetime.strptime(_date, '%Y%m%d')
     if isinstance(_date, datetime.datetime) or isinstance(
             _date, datetime.date):
         _date = date2num(_date)
     return _date
Ejemplo n.º 29
0
def historico():
    symbol = input("Input a symbol: ")
    historico = DatabaseActions.getHistoric(symbol)
    historicDF = {}
    for key in historico:
        historicDF[datetime.datetime.fromisoformat(key)] = historico[key]
    df = pd.DataFrame.from_dict(historicDF,
                                orient='index').tail(50).rename(columns={
                                    'o': 'Open',
                                    'h': 'High',
                                    'l': 'Low',
                                    'c': 'Close'
                                })

    op = input("¿Agregar RSI? S/N: ")
    if op.lower() == 's':
        titulo = 'RSI'
        periodo = int(input("Ingrese el periodo: "))
        RSI = RelativeStrengthIndex.RSI(historico, periodo)
        df[titulo] = df.index.to_series().map(RSI)

    op = input("¿Agregar EMA? S/N: ")
    while op.lower() == 's':
        titulo = input("Ingrese un titulo para la EMA: ")
        periodo = int(input("Ingrese el periodo: "))
        EMAS = ExponentialMovingAverage.EMA(historico, periodo)
        df[titulo] = df.index.to_series().map(EMAS)
        op = input("¿Agregar otra EMA? S/N: ")

    print(df)
    data = df.tail(30)
    columns = list(data.columns)[4:]
    fig = plt.figure()
    fig.set_size_inches((20, 16))
    ax_candle = fig.add_axes((0, 0.05, 1, 0.9))
    ax_candle.xaxis_date()
    if 'RSI' in columns:
        ax_candle = fig.add_axes((0, 0.30, 1, 0.7))
        ax_rsi = fig.add_axes((0, 0.05, 1, 0.2), sharex=ax_candle)
        ax_rsi.set_ylabel("(%)")
        ax_rsi.plot(data.index, [70] * len(data.index), label="overbought")
        ax_rsi.plot(data.index, [30] * len(data.index), label="oversold")
        ax_rsi.plot(data.index, data["RSI"], label="RSI")
        ax_rsi.legend(loc="center left")

    ohlc = []
    for date, row in data.iterrows():
        Open, High, Low, Close = row[:4]
        ohlc.append([date2num(date), Open, High, Low, Close])

    for column in columns:
        if column != 'RSI':
            ax_candle.plot(data.index, data[column], label=column)
    candlestick_ohlc(ax_candle, ohlc, colorup="g", colordown="r")
    ax_candle.legend()
    plt.show()
Ejemplo n.º 30
0
def date_to_num(dates):
    num_time = []
    for date in dates:
        #为什么int转换后会有.0这样的问题
        date = (str)(date)
        date = date[:-2]
        date_time = datetime.datetime.strptime(date, '%Y%m%d')
        num_date = date2num(date_time)
        num_time.append(num_date)
    return num_time
Ejemplo n.º 31
0
    def get_current_selection(self):
        """
        Returns a mask array where 1 == selected data point and 0 == not 
        selected data point. 
        """
        xdata, ydata = self.series.get_data()
        selection_mask = numpy.zeros(len(xdata), dtype='int')

        #if xdata are datetimes, then need to convert them to numbers
        #first
        if len(xdata) > 0 and type(xdata[0]) is datetime.datetime:
            xdata = numpy.array([date2num(d) for d in xdata])

        #if ydata are datetimes, then need to convert them to numbers
        #first
        if len(ydata) > 0 and type(ydata[0]) is datetime.datetime:
            ydata = numpy.array([date2num(d) for d in ydata])

        if self.direction == 'rectangular':
            for xmin_sel, ymin_sel, xmax_sel, ymax_sel in self.current_selection:
                tmp_mask = numpy.where(
                    numpy.logical_and(
                        numpy.logical_and(xdata >= xmin_sel,
                                          xdata <= xmax_sel),
                        numpy.logical_and(ydata >= ymin_sel,
                                          ydata <= ymax_sel)))

                selection_mask[tmp_mask] = 1

        elif self.direction == 'horizontal':
            for xmin_sel, ymin_sel, xmax_sel, ymax_sel in self.current_selection:
                tmp_mask = numpy.where(
                    numpy.logical_and(xdata >= xmin_sel, xdata <= xmax_sel))
                selection_mask[tmp_mask] = 1

        else:
            for xmin_sel, ymin_sel, xmax_sel, ymax_sel in self.current_selection:
                tmp_mask = numpy.where(
                    numpy.logical_and(ydata >= ymin_sel, ydata <= ymax_sel))
                selection_mask[tmp_mask] = 1

        return selection_mask
Ejemplo n.º 32
0
def get_one(gu_piao):
    sql = 'SELECT mai_chu_er,mai_ru_er,date,shou_pan_jia FROM shen_zheng_gushi.shen_gutong where dai_ma=%s;'
    cur.execute(sql, (gu_piao))
    result = cur.fetchall()
    money_data_list = []
    for i in result:
        t = date2num(i[2])
        jin_er_du = i[1] - i[0]
        shou_pan_jia = i[3]
        money_data_list.append((t, shou_pan_jia, jin_er_du))
    return money_data_list
Ejemplo n.º 33
0
    def get_current_selection(self):
        """
        Returns a mask array where 1 == selected data point and 0 == not 
        selected data point. 
        """    
        xdata, ydata = self.series.get_data()
        selection_mask = numpy.zeros(len(xdata),dtype='int')
        
        #if xdata are datetimes, then need to convert them to numbers
        #first
        if len(xdata)>0 and type(xdata[0]) is datetime.datetime:
            xdata = numpy.array([date2num(d) for d in xdata])
        
        #if ydata are datetimes, then need to convert them to numbers
        #first
        if len(ydata)>0 and type(ydata[0]) is datetime.datetime:
            ydata = numpy.array([date2num(d) for d in ydata])
        
        if self.direction == 'rectangular':
            for xmin_sel, ymin_sel, xmax_sel, ymax_sel in self.current_selection:
                tmp_mask = numpy.where(numpy.logical_and(numpy.logical_and(xdata >= xmin_sel, 
                                                                           xdata <= xmax_sel),
                                                         numpy.logical_and(ydata >= ymin_sel,
                                                                           ydata <= ymax_sel)))

                selection_mask[tmp_mask] = 1
                
        elif self.direction == 'horizontal':
            for xmin_sel, ymin_sel, xmax_sel, ymax_sel in self.current_selection:
                tmp_mask = numpy.where(numpy.logical_and(xdata >= xmin_sel, 
                                                         xdata <= xmax_sel))
                selection_mask[tmp_mask] = 1
        
        else:
            for xmin_sel, ymin_sel, xmax_sel, ymax_sel in self.current_selection:
                tmp_mask = numpy.where(numpy.logical_and(ydata >= ymin_sel, 
                                                         ydata <= ymax_sel))
                selection_mask[tmp_mask] = 1
        
        return selection_mask
Ejemplo n.º 34
0
def str_epoch2num(s):
    """
    input is either a string or and time in seconds since epoch
    output is the date format of matplotlib
    Without a timezone in the input string, the local timezone is used.
    To enter a timezone you can use UTC, GMT,Z or something like
    -0500. It also knows about EST and DST.
    """
    if isinstance(s, basestring):
        # we replace pylab.datestr2num to better handle local timezone
        dt = dateutil.parser.parse(s, tzinfos=_TZOFFSETS)
        if dt.tzinfo is None:
            dt = dt.replace(tzinfo=dateutil.tz.tzlocal())
        return pylab.date2num(dt)
    else:
        return pylab.epoch2num(s)
Ejemplo n.º 35
0
def draw():
    #获取时间轴
    date_num = len(get_data_source('date'))
    today = datetime.today() if LOG_DATE is 'today' else str2datetime(LOG_DATE)
    x_time =[today+timedelta(-i) for i in range(date_num)] 
    dates = pl.date2num(x_time)
    #创建图1
    pl.figure(1)
    #子图1
    ax1 = pl.subplot(2,2,1)    
    update_list = get_data_source('number')
    ax1.plot_date(dates,  update_list,  'r-',  marker='.',  linewidth=1)
    ax1.xaxis.set_major_formatter( DateFormatter('%m.%d'))
    pl.xlabel('date')
    pl.ylabel('album number')
    pl.title('the number of album db')
    #子图2
    ax2 = pl.subplot(2,2,2)
    insert_list = get_data_source('insert')
    ax2.plot_date(dates,  insert_list,  'b-',  marker='*',  linewidth=1)
    ax2.xaxis.set_major_formatter( DateFormatter('%m.%d') )
    pl.xlabel('date')
    pl.ylabel('increasement')
    pl.title('daily album increasement')
    #子图3
    ax3 = pl.subplot(2,2,3)
    err_num_list = get_data_source('error_num')
    ax3.plot_date(dates,  err_num_list,  'y-',  marker='+',  linewidth=1)
    ax3.xaxis.set_major_formatter( DateFormatter('%m.%d') )
    pl.xlabel('date')
    pl.ylabel('error')
    pl.title('occurred errors')
    #子图4
    ax4 = pl.subplot(2,2,4)
    err_num_list = get_data_source('update')
    ax4.plot_date(dates,  err_num_list,  'g-',  marker='^',  linewidth=1)
    ax4.xaxis.set_major_formatter( DateFormatter('%m.%d') )
    pl.xlabel('date')
    pl.ylabel('update')
    pl.title('updated albums')
    
    pl.figure(1).autofmt_xdate()
    pl.figure(1).tight_layout()
    pl.savefig(IMAGE_PATH,dpi=DPI)
Ejemplo n.º 36
0
conn = sqlite3.connect('data_log.db')
c = conn.cursor()
c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE '28.%';")
sensors = []
for row in c:
	sensors.append(row[0])

print(sensors)

sdates = [];
svalues = [];
i = 1

for s in sensors:
	c.execute("SELECT `datetime`, value FROM `%s` ORDER BY `datetime` DESC LIMIT 150" % (sensors[i-1]))
	dates = []
	values = []

	for row in c:
		dates.append(dateutil.parser.parse(row[0]))
		values.append(row[1])
		
	plo = pyplot.subplot(310+i)
	if i < 3:
		pylab.setp( plo.get_xticklabels(), visible=False)
	plo.plot_date(pylab.date2num(dates),values)
	i=i+1

pyplot.show()
Ejemplo n.º 37
0
    def plot(self, xticks=None, xlabel=None, ylabel=None, title='',
             grid=True, climits=None, figsize=None, origin=None,
             xtickrotation=0, cmap='jet', showcolorbar=True, ax=None,
             show_uncertainties=False, norm_uncertainties=False,
             input=None, showxticks=True, nclasses=11, lat_tick=np.arange(-90., 90 + 30., 30.),
             monthsamp=1, yearonly=True):
        """
        Generates a Hovmoeller plot

        Two different options are available to generate the plot. The plot can be either based on calculation from
        the Hovmoeller class itself. This requires that self.hov was calculated already using e.g. time_to_lat().
        The second option is, that a Data object is provided by the *input* variable. In this case, the zonal mean is calculated from
        the Data object all required processing is done in this routine.

        input : Data
            C{Data} object that is used for the generation of the hovmoeller plot
        grid : bool
            plot tick grid in hovmoeller plot
        ylabel : str
            ylabel for plot
        title : str
            title for the plot
        climits : list
            limits for the colorbar; [vmin,vmax]
        cmap : str
            colormap to be used
        xtickrotation : float
            rotation of xticklabels 0 ... 90
        showcolorbar : bool
            show colorbar in plot
        ax : axis
            axis to plot to. If not specified (default), then a new figure will be created
        showxticks : bool
            show the xticks in the Hovmoeller plot
        nclasses : int
            number of classes for colorbar
        lat_tick : ndarray
            tick labels for latitude (default: every 30 degree)
        monthsamp : int
            sampling interval for months
        yearonly : bool
            if True, then only the years are shown as labels in the timeseries

        input is expected to have dimensions [nlat,ntime] and can be precalculated using Data.get_zonal_mean().T
        input is expected to be a Data object!

        """

        if input is not None:
            if self.hov is not None:
                raise ValueError(
                    'If precalculated dat is provided as input, the data MUST not be calculated already by the class!')
            else:
                #////////////////////////////////////////////////
                # HOVMOELLER PLOT FROM DATA OBJECT
                #////////////////////////////////////////////////

                input1 = input.get_zonal_mean(return_object=True)
                input1.adjust_time(day=1)  # , month=1)

                nlat, nt = input1.data.shape
                if nt != len(self.time):
                    print input1.shape
                    print nt, len(self.time)
                    raise ValueError('inconsistent time shape!')

                self.hov = input1.data
                self.yearonly = yearonly

                #/// check if latitudes are in increasing order ?
                lats = input1.lat * 1.
                if np.all(np.diff(lats) >= 0):
                    f_invert = False

                else:
                    f_invert = True
                    # change sequence of data!
                    lats = lats[::-1]

                    if not np.all(np.diff(lats) >= 0):
                        raise ValueError(
                            'Latitudes can not be put into ascending order!')

                #/// monthly ticks ///
                # convert times to monthly; apply date conversions to ensure
                # that generate_monthly_timeseries() can work following the
                # python convention
                data_days = generate_monthly_timeseries(
                    pl.date2num(input1.date))
                all_days = np.unique(data_days)
                if showxticks:
                    self.generate_xticks(all_days, monthsamp=monthsamp)

                # use only ticks that are within the current latitudes
                mlat = (lat_tick >= lats.min()) & (lat_tick <= lats.max())
                lat_tick1 = lat_tick[mlat]

                # interpolate the tick grid to the data grid
                # index positions
                lat_pos = np.interp(lat_tick1, lats, np.arange(len(lats)))

                if f_invert:  # invert position back
                    #lat_tick = lat_tick[::-1]
                    lat_pos = lat_pos[::-1]

                yticklabels = np.asarray(map(str, lat_tick1))

                if self.transpose:
                    scal = self.rescalex
                else:
                    scal = self.rescaley

                yticks = lat_pos * scal

                self.y_major_locator = pl.FixedLocator(yticks)
                self.y_major_formatter = pl.FixedFormatter(yticklabels)

                ylabel = 'latitude'

        if climits is None:
            raise ValueError('Hovmoeller, please specify climits')

        if xlabel is None:
            self.xlabel = 'x-label'
        else:
            self.xlabel = xlabel

        if figsize is None:
            if self.transpose:
                figsize = (6, 11)
            else:
                figsize = (12, 4)

        if ylabel is None:
            self.ylabel = 'y-label'
        else:
            self.ylabel = ylabel

        self.title = title

        if ax is None:
            self.fig = pl.figure(figsize=figsize)
            self.ax = self.fig.add_subplot(111)
        else:
            self.ax = ax
            self.fig = self.ax.figure

        if self.transpose:
            arr = self.hov.repeat(self.rescalex, axis=0).repeat(
                self.rescaley, axis=1)
            self.im = self.ax.imshow(arr.T, interpolation='Nearest', origin=origin, vmin=climits[
                                     0], vmax=climits[1], cmap=pyplot.get_cmap(cmap, nclasses))
        else:
            # rescale array for visualization
            arr = self.hov.repeat(self.rescaley, axis=0).repeat(
                self.rescalex, axis=1)
            self.im = self.ax.imshow(arr, interpolation='Nearest', origin=origin, cmap=pyplot.get_cmap(
                cmap, nclasses), vmin=climits[0], vmax=climits[1])

            if (show_uncertainties) & (self.hov_var is not None):
                arr1 = self.hov_var.repeat(
                    self.rescaley, axis=0).repeat(self.rescalex, axis=1)

                if norm_uncertainties:
                    # normalized by variance
                    arr1 = arr / arr1
                self.ax.contour(arr1, linestyles='-', colors='black')

        if xlabel is not None:
            self.ax.set_xlabel(self.xlabel)
        if ylabel is not None:
            self.ax.set_ylabel(self.ylabel)
        self.ax.set_title(self.title)

        #/// ticks
        if self.transpose:
            self.ax.yaxis.set_major_locator(self.x_major_locator)
            self.ax.yaxis.set_major_formatter(self.x_major_formatter)

            self.ax.xaxis.set_major_locator(self.y_major_locator)
            self.ax.xaxis.set_major_formatter(self.y_major_formatter)
        else:
            self.ax.yaxis.set_major_locator(self.y_major_locator)
            self.ax.yaxis.set_major_formatter(self.y_major_formatter)

            if showxticks:
                self.ax.xaxis.set_major_locator(self.x_major_locator)
                self.ax.xaxis.set_major_formatter(self.x_major_formatter)

        if showxticks:
            # pl.xticks(rotation=xtickrotation)
            for t in self.ax.get_xticklabels():
                t.set_rotation(xtickrotation)
        else:
            self.ax.set_xticks([])

        if xticks is not None:
            nx = 2
            set_label(nx)

        if grid:  # show grid
            self.ax.grid(color='white', linewidth=1, linestyle='-')

        #/// colorbar
        if showcolorbar:
            if self.transpose:
                self.fig.colorbar(self.im, orientation='vertical', shrink=0.5)
            else:
                # only do import here, as it does not work otherwise (todo)
                from plots import add_nice_legend
                add_nice_legend(self.ax, self.im,
                                pyplot.get_cmap(cmap, nclasses))
Ejemplo n.º 38
0
    def __init__(self, time, value, var_unc=None, rescalex=1,
                 rescaley=1, lat=None, lon=None, transpose=False,
                 use_cdo=True):
        """
        Hovmoeller class

        This class implements the functionality to generate hovmoeller
        plots. It allows to calculate all relevant data by itself or
        using the CDO's for calculation of e.g. zonal means

        time : datetime
            vector with time information
        value : ndarray
            data to be analyzed. if the argument lat is provided it is
            assumed that lat/lon are 2D matrices
            In this case the value is expected to be a 3D variables as
            value(time,ny,nx)
        var_unc : ndarray
            additional array with variance information (can be used to
            show uncertainties) - not really validated so far
        rescalex : int
            rescaling factor for x-variable (used to blow up the plot)
        rescaley : int
            rescaling factor for y-variable (used to blow up the plot)
        lat : ndarray
            latitude coordinates
        lon : ndarray
            longitude coordinates
        transpose : bool
            transpose the data matrix

        EXAMPLES
        ========

        #a minimum example for a time-latitude plot
        #get data from e.g. file; here random data
        t1=datestr2num('2011-05-01'); t2=datestr2num('2011-08-31')
        d = num2date(linspace(t1,t2,1000.))
        lats=linspace(-90.,90.,181) + 0.5; lats = lats[:-1]
        lons = linspace(-180.,180.,361) + 0.5; lons = lons[:-1]

        LONS,LATS = meshgrid(lons,lats)
        ny,nx = LATS.shape; nt = len(d)
        dat = rand(nt,ny,nx)

        #create a hovmoeller object
        myhov = hovmoeller(d,dat,lat=LATS,rescaley=20,rescalex=10)
        myhov.time_to_lat(dlat=1.,yticksampling=1)
        myhov.plot(title='Test Hovmoeller plot',ylabel='lat',xlabel='days',origin='lower',xtickrotation=30,climits=[-1.,1.])
        show()

        Another example, that does NOT calculate the hovmoeller plot by itself, but uses functionality from pyCMBS Data object

        file='wachmos_sm_1978-2010_int_monthly_t63.nc'
        D = Data(file,'var100',read=True)

        myhov = hovmoeller(num2date(D.time),None,rescaley=20,rescalex=20)
        myhov.plot(climits=[0.,0.5],input=D,xtickrotation=90,cmap='jet_r')
        show()


        """

        #/// check consistency ///
        if value is not None:
            if len(time) == len(value):
                pass
            else:
                sys.exit('Inconsistent sizes of time and value (hovmoeller)')

        if lat is not None and shape(lat) != shape(value[0, :, :]):
            print shape(lat), shape(value[0, :, :])
            sys.exit('Inconsistent latitudes and data (hovmoeller)')

        #/// set values of class ///
        self.time = time
        self.transpose = transpose
        ntim = len(self.time)

        t = pl.date2num(time)
        self.t_min = pl.num2date(np.floor(t.min()))
        self.t_max = pl.num2date(np.ceil(t.max()))

        if value is not None:
            self.value = value.copy()
            self.value = ma.array(self.value, mask=isnan(self.value))
            # now reshape everything to [time,ngridcells]
            self.value.shape = (ntim, -1)

        if var_unc is None:
            self.var_unc = None
        else:
            self.var_unc = var_unc.copy()
            self.var_unc.shape = (ntim, -1)

        self.hov_var = None

        self.rescalex = rescalex
        self.rescaley = rescaley

        if lat is not None:
            self.lat = lat.copy()
            self.lat.shape = (-1)
        else:
            self.lat = None

        if lon is not None:
            self.lon = lon.copy()
            self.lon.shape = (-1)
        else:
            self.lon = None

        self.hov = None