首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >波基烛台在蜡烛之间创造了很小的间隙

波基烛台在蜡烛之间创造了很小的间隙
EN

Stack Overflow用户
提问于 2021-04-02 18:45:12
回答 1查看 223关注 0票数 0

我有一个烛台图表,与波基很好地工作。唯一的问题是我的数据是1分钟的数据和图表可以看起来有点挤在一起。在烛台的酒吧之间是否有一个小的缺口?

更新-代码

代码语言:javascript
复制
import pandas as pd

from datetime import timedelta

from bokeh.plotting import figure, ColumnDataSource
from bokeh.models.widgets import Dropdown
from bokeh.io import curdoc
from bokeh.layouts import column

from bokeh.models import BooleanFilter, CDSView, Select, Range1d, HoverTool
from bokeh.palettes import Category20
from bokeh.models.formatters import NumeralTickFormatter
from bokeh.io import output_file, show

# Define constants
W_PLOT = 1700
H_PLOT = 600
TOOLS = "pan,box_zoom,zoom_in,zoom_out,redo,undo,reset,save,crosshair"

VBAR_WIDTH = 60*60*10000
# VBAR_WIDTH =  12*60*60*1000 # half day in ms
# VBAR_WIDTH =  24*60*60*1000 # day in ms

RED = Category20[7][6]
GREEN = Category20[5][4]

def plot_test(df: pd.DataFrame,
          name: str) -> None:

inc = df.price_close > df.price_open
dec = ~inc

cds = ColumnDataSource(data=df)   
view_inc = CDSView(source=cds, filters=[BooleanFilter(inc)])
view_dec = CDSView(source=cds, filters=[BooleanFilter(dec)])    

fig = figure(plot_width=W_PLOT, plot_height=H_PLOT, 
             tools=TOOLS,
             x_axis_type="datetime",
             title=name,
             toolbar_location='above')

# Plot candles
# High and low
fig.segment(x0='time_stamp', y0='price_high', 
            x1='time_stamp', y1='price_low', 
            source=cds, view=view_inc, 
            color='black')
fig.segment(x0='time_stamp', y0='price_high', 
            x1='time_stamp', y1='price_low', 
            source=cds, view=view_dec,
            color='black')

# Open and close
r1 = fig.vbar(x='time_stamp', width=timedelta(minutes=1), 
         top='price_open', bottom='price_close', 
              source=cds, view=view_inc,
              fill_color=GREEN, line_color="black")
r2 = fig.vbar(x='time_stamp', width=timedelta(minutes=1), 
         top='price_open', bottom='price_close', 
              source=cds, view=view_dec,
              fill_color=RED, line_color="black")

# let add a moving average
fig.line(x='time_stamp', y='ma_20', source=cds, legend_label='MA 20')

# entry signals
fig.triangle(x='time_stamp', y='buy', source=cds, fill_color=GREEN,
             size=10)
fig.inverted_triangle(x='time_stamp', y='sell', source=cds, 
                      fill_color=RED, size=10)

# Set up the hover tooltip to display some useful data
fig.add_tools(HoverTool(
    renderers=[r1],
    tooltips=[
        ("Open", "@price_open{0.0000}"),
        ("High", "@price_high{0.0000}"),
        ("Low", "@price_low{0.0000}"),
        ("Close", "@price_close{0.0000}"),
        ("Date", "@time_stamp{%Y-%m-%d %H:%M}"),
    ],
    formatters={
        '@time_stamp': 'datetime'
        }))

fig.add_tools(HoverTool(
    renderers=[r2],
    tooltips=[
        ("Open", "@price_open{0.0000}"),
        ("High", "@price_high{0.0000}"),
        ("Low", "@price_low{0.0000}"),
        ("Close", "@price_close{0.0000}"),
        ("Date", "@time_stamp{%Y-%m-%d %H:%M}"),
    ],
    formatters={
        '@time_stamp': 'datetime'
        }))

elements = list()
elements.append(fig)

curdoc().add_root(column(elements))
curdoc.title = 'Blah'

show(fig)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-06 16:35:45

正如我指出的那样,为了改变烛台的宽度,它是通过设置vbar方法的宽度参数来完成的。

下面的数字是好的日常数据。对于更高频率的数据,我会减少“12”

VBAR_WIDTH = 12_60_60*1000 #半天,以毫秒计

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66923858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档