AmazonAlert.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:Amazon-Alert 作者: anfederico 项目源码 文件源码
def plotDatePrice(productID, productTitle, data):

    # Data setup 
    x, y = [], []
    for datapoint in data:
        date = datapoint.split('|')[0]
        price = float(datapoint.split('|')[1])
        x.append(dt.datetime.strptime(date, '%Y-%m-%d'))
        y.append(price)     
    x = matplotlib.dates.date2num(x)    
    x_np, y_np = np.array(x), np.array(y)   

    # Plot setup
    ax = plt.figure(figsize=(6, 3)).add_subplot(111)
    ax.spines['top'].set_visible(False)   
    ax.spines['right'].set_visible(False)   
    ax.get_xaxis().tick_bottom()  
    ax.get_yaxis().tick_left()   
    ax.plot(x_np, y_np, color='lightblue', lw=2)
    ax.margins(0.05)  
    ax.yaxis.set_major_formatter(FuncFormatter(lambda x, pos: ('$%i' % (x))))
    ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
    plt.yticks(fontsize=8)
    plt.ylim(ymin=min(y)*0.7, ymax=max(y)*1.3)
    plt.title('Recent Price History\n'+productTitle, weight ='light', fontsize=12, y=1.08)  
    plt.xticks(rotation=40, fontsize=7) 
    plt.tight_layout()
    plt.savefig(productID+'.png')
    return productID+'.png'

# ----- Email Configuration ----------------------------------------------------
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号