Hello,
an example using DateGapTickFormatter used to work in 0.12.3, not in 0.12.4rc1.
The errors are a bit cryptic. Hopefully a simple bug / a simple cure.
Code below.
Thx !
Complaints in the javascript console:
TypeError: DateGapTickFormatter.define is not a function. (In 'DateGapTickFormatter.define({
date_labels: [p.Any]
})’, ‘DateGapTickFormatter.define’ is undefined)
Error: Model `DateGapTickFormatter’ does not exists. The problem may be two fold. Either a model was requested that’s available in an extra bundle, e.g. a widget, or a custom model was requested, but it wasn’t registered before first usage.
Code:
from math import pi
import pandas as pd
from bokeh.models.formatters import TickFormatter, String, List
from bokeh.plotting import figure, show, output_file
from bokeh.sampledata.stocks import MSFT
from bokeh.io import curdoc,output_file, show
class DateGapTickFormatter(TickFormatter):
date_labels = List(String)
implementation = “”"
_ = require “underscore”
Model = require “model”
p = require “core/properties”
class DateGapTickFormatter extends Model
type: ‘DateGapTickFormatter’
doFormat: (ticks) →
date_labels = @date_labels
return (date_labels[tick] ? “” for tick in ticks)
@define {
date_labels: [ p.Any ]
}
module.exports =
Model: DateGapTickFormatter
“”"
df = pd.DataFrame(MSFT)[:50]
date_labels = [date.strftime(’%b %d’) for date in pd.to_datetime(df[“date”])]
mids = (df.open + df.close)/2
spans = abs(df.close-df.open)
inc = df.close > df.open
dec = df.open > df.close
w = 0.5
TOOLS = “pan,wheel_zoom,box_zoom,reset,save”
p = figure(tools=TOOLS, plot_width=1000, title=“MSFT Candlestick with Custom X-Axis”)
p.xaxis.major_label_orientation = pi/4
p.grid[0].ticker.desired_num_ticks = 6
p.xaxis[0].formatter = DateGapTickFormatter(date_labels = date_labels)
p.segment(df.index, df.high, df.index, df.low, color=“black”)
p.rect(df.index[inc], mids[inc], w, spans[inc], fill_color="#D5E1DD", line_color=“black”)
p.rect(df.index[dec], mids[dec], w, spans[dec], fill_color="#F2583E", line_color=“black”)
curdoc().add_root(p)