当输入某些股票时,散景图变得失真

时间:2018-08-07 18:15:45

标签: python plot bokeh interactive stocks

我正在使用Bokeh在python中显示股票数据,并添加了一个下拉菜单,用于选择股票行情自动收录器,从而在图表上显示所选股票的收盘价和日期。

某些股票按预期显示(例如,Agilent Technologies),而其他股票的数据则显示在y轴变形的地方(例如,Amazon Inc.)。最好使用下面的两个图来说明:

与某些股票相比,哪些显示?

enter image description here

在这里,y轴以某种方式显着拉伸,并且值是相反的顺序。

我在本节中的代码如下:

p=figure(
    height=400,
    x_axis_type='datetime',
    y_axis_type='linear',
    title=(company+' ('+tickerstring+') '),
    tools='pan, box_zoom, wheel_zoom, reset',
)


x = np.array(sandpdates, dtype=np.datetime64)
y=sandpclose
r=p.line(x, y)


p.grid.grid_line_color="white"
p.xaxis.axis_label = 'Date'
p.yaxis.axis_label = 'Price'
p.add_tools(HoverTool(
    tooltips=[
        ("Date", "@x{%F}"),
        ('Close',"@y")
    ],
    formatters={
        'x':'datetime', # use 'datetime' formatter for 'date' field
    },
    mode='vline'
))




def update(f, startyear=2015, startmonth=1, startday=1, endyear=current_year, endmonth=current_month, endday=current_day):
    fstocksymbol=str(f.upper())
    starts=dt.datetime(startyear,startmonth,startday)
    end = dt.datetime(endyear,endmonth,endday)
    if int(startyear)> int(endyear):
        print('Please ensure the starting date does not exceed the end date')
    elif int(startyear)==int(endyear):
        if startmonth>endmonth:
            print('Please ensure the starting date does not exceed the end date')
        elif startmonth==endmonth:
            if startday>endday:
                print('Please ensure the starting date does not exceed the end date')
    else:
        print('')
    if fstocksymbol in stocksymbols:
        p.title.text = (symbolsdictionary[fstocksymbol]).upper()+' ('+fstocksymbol+')'
        tickerstring=fstocksymbol
        firstfunction=stockname(tickerstring, starts, end)
        secondfunction=stockdata(firstfunction)
        stockdates=[]
        stockcloseprices=[]
        for value in secondfunction:
            stockdates.append(value[0])
            stockcloseprices.append(value[4])
        finaldate=np.array(stockdates, dtype=np.datetime64)
        r.data_source.data['x'] = finaldate
        r.data_source.data['y'] = stockcloseprices
        push_notebook()
    elif fstocksymbol=='':
        print('')
    else:
        print("")


interact(update, f=stocksymbols, startyear=list(range(int(current_year-5),int(current_year+1))), startmonth=list(range(1,13)), startday=list(range(1,32)), 
         endyear=list(range(int(current_year-5),int(current_year+1))), endmonth=list(range(1,13)), endday=list(range(1,32)))

grid = gridplot([p, b], ncols=2, plot_width=570, plot_height=400)
show(grid, notebook_handle=True)

什么可能导致此问题,并且有什么必要的措施来解决此问题?

0 个答案:

没有答案