叠加静态散景图

时间:2015-11-14 13:08:40

标签: python python-3.x bokeh

我试图叠加散景图。

这一个在上面: http://bokeh.pydata.org/en/latest/docs/gallery/image_rgba.html

以下这个: http://bokeh.pydata.org/en/latest/docs/gallery/stocks.html

反之亦然。

我将x轴更改为日期时间以适合股票图。但到目前为止,这是一个空白的图表。有什么建议吗?

import numpy as np
import arrow
import pandas as pd
import pandas.io.data as web
#from pandas_data_reader import data as web
from pandas import DataFrame, Series

from bokeh.io import output_notebook
output_notebook()
from bokeh.plotting import figure, show, output_file, gridplot

p1 = figure(x_axis_type = "datetime", responsive=True)


N = 100
M = 100
img = np.empty((N,M), dtype=np.uint32)
view = img.view(dtype=np.uint8).reshape((N, M, 4))
for i in range(N):
    for j in range(M):
            view[i, j, 0] = 0  #red
            view[i, j, 1] = int(i/N*160)  #green
            view[i, j, 2] = int(j/N*255)  #blue
            view[i, j, 3] = int(i/N*255)  #alpha

p1 = figure(x_range=['10/1/2015','11/1/2015'], y_range=[0,200]) #changes the view window

all_data = {} 
for ticker in ['AAPL', 'IBM', 'MSFT', 'GOOG']:
    all_data[ticker] = web.get_data_google(ticker, '10/1/2015', '11/1/2015')
AAPL = Series(all_data['AAPL']['Close'])
GOOG = Series(all_data['GOOG']['Close'])
MSFT = Series(all_data['MSFT']['Close'])
IBM = Series(all_data['IBM']['Close'])
p1.line(AAPL.index, AAPL, color='#A6CEE3', legend='Apple')
p1.line(IBM.index, IBM, color='#0022CC', legend='IBM')
p1.line(MSFT.index, MSFT, color='#3322DD', legend='MICROSOFT')

p1.title = "Superimposed info"

p1.image_rgba(image=[img], x=['10/1/2015'], y=[10], dw=['10/15/2015'], dh=[10]) 
p = gridplot([[p1]], toolbar_location=None, min_border=0, h_symmetry=True)
show(p)

1 个答案:

答案 0 :(得分:2)

是你的意思叠加? enter image description here

如果这里的情况是我使用的大部分代码所使用的代码片段,我只是更改了调用以获取数据,因为我在代理后面并且无法获取它;):

from __future__ import division
import pandas as pd
import numpy as np
from pandas import Series
from bokeh.plotting import figure, show, output_file

N = 100
img = np.empty((N,N), dtype=np.uint32)
view = img.view(dtype=np.uint8).reshape((N, N, 4))
for i in range(N):
    for j in range(N):
        view[i, j, 0] = int(i/N*255)
        view[i, j, 1] = 158
        view[i, j, 2] = int(j/N*255)
        view[i, j, 3] = 255

output_file("image_rgba.html", title="image_rgba.py example")

print img.shape
p = figure(x_range=[0,20], y_range=[0,160])
p.image_rgba(image=[img], x=[0], y=[0], dw=[20], dh=[160])


all_data = {}
for ticker in ['AAPL', 'IBM', 'MSFT', 'GOOG']:
    # all_data[ticker] = web.get_data_google(ticker, '10/1/2015', '11/1/2015')
    path = 'C:/Users/myuser/Downloads/' + ticker.lower() + '.csv'
    all_data[ticker] = pd.read_csv(path)

AAPL = Series(all_data['AAPL']['Close'])
GOOG = Series(all_data['GOOG']['Close'])
MSFT = Series(all_data['MSFT']['Close'])
IBM = Series(all_data['IBM']['Close'])

p.line(AAPL.index, AAPL, color='#A6CEE3', legend='Apple')
p.line(IBM.index, IBM, color='#0022CC', legend='IBM')
p.line(MSFT.index, MSFT, color='#3322DD', legend='MICROSOFT')

show(p)  # open a browser

编辑:p = figure(x_range=[0, 20], y_range=[0, 160], x_axis_type="datetime")会将x_axis更改为datetime对象,但您的数据索引是整数,因此1到20将显示为自纪元以来的秒数并看到issue:我认为你将无法将斧头显示为dd / mm / yyyy或者你想要的任何格式。