Hi all,
First of all thanks for developing Bokeh, I found it very powerful and useful to a data plotting and moreover plot customization with widgets.
As usual I’m trying to make custom tick labels along X axis, I used the 3 bars plotting example from here: http://stackoverflow.com/questions/37173230/how-do-i-use-custom-labels-for-ticks-in-bokeh
but because I need run bokeh server (not html like in the example), I did the following instructions from here: https://github.com/bokeh/bokeh/issues/3930
Like the-neworder suggested I created a new module with FixedTickFormatter:
from bokeh.util.compiler import CoffeeScript
from bokeh.core.properties import Dict, Int, String
from bokeh.models import TickFormatter
class FixedTickFormatter(TickFormatter):
"""
Class used to allow custom axis tick labels on a bokeh chart
Extends bokeh.model.formatters.TickFormatter
"""
COFFEESCRIPT = """
import {Model} from "model"
import * as p from "core/properties"
export class FixedTickFormatter extends Model
type: 'FixedTickFormatter'
doFormat: (ticks) ->
labels = @get("labels")
return (labels[tick] ? "" for tick in ticks)
@define {
labels: [ p.Any ]
}
"""
labels = Dict(Int, String, help="""
A mapping of integer ticks values to their labels.
""")
__implementation__ = CoffeeScript(COFFEESCRIPT)
and run Bokeh server like it explained inside the link above: bokeh serve visualize_server.py and so on...
This new module was found successfully and works fine for html (3 bars with custom labels were shown), but not for server. The code is below:
import pandas as pd
from bokeh.charts import Bar, output_file, show
from bokeh.client import push_session
from bokeh.plotting import curdoc, figure
from custom_ticks import FixedTickFormatter
from bokeh.layouts import layout
skills_list = [‘cheese making’, ‘squanching’, ‘leaving harsh criticisms’]
pct_counts = [25, 40, 1]
df = pd.DataFrame({‘skill’:skills_list, ‘pct jobs with skill’:pct_counts})
p = Bar(df, ‘index’, values=‘pct jobs with skill’, title=“Top skills for ___ jobs”, legend=False)
label_dict = {}
for i, s in enumerate(skills_list):
label_dict[int(i)] = str(s)
print label_dict
p.xaxis[0].formatter = FixedTickFormatter(labels=label_dict)
output_file(“bar.html”)
show(p)
‘’’
session = push_session(curdoc(), app_path=“/visualization_server”)
l = layout([[p]], sizing_mode=‘fixed’)
session.show(l)
session.loop_until_closed()
‘’’
In case of session using:
> ```
> ```
>
>
> ```
> ```
> ```
> session = push_session(curdoc(), app_path="/visualization_server")
> ```
> ```
> ```
> l = layout([[p]], sizing_mode='fixed')
> ```
> ```
> ```
> session.show(l)
> ```
> ```
> ```
> session.loop_until_closed()
> ```
I’ve got: DeserializationError(u’Int expected Integral, got1’,)
Could you please give an idea why? I have seen similar problem here: https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/zUE0i7LYwQg
But as it looks for me it’s another situation. Thank you!