FuncTickFormatter

I need to assign custom labels stored in a dictionary to
graph axis. The following code used to work before the 0.12.9 release.

Xlabel = {1:‘one’,2:‘two’,3:‘three’}

p.xaxis.formatter =
FuncTickFormatter(code="""

var labels
= %s

return
labels[tick]

“”"
% Xlabel)

Could someone tell me how to adjust the code?

Thank you!

Can you provide a minimal example that doesn’t work for you?

This code:

from bokeh.io import show, output_file
from bokeh.models import FuncTickFormatter
from bokeh.plotting import figure

f = figure()
Xlabel = {1: 'one', 2: 'two', 3: 'three'}
f.xaxis.formatter = FuncTickFormatter(code="""
            var labels = %s;
            return labels[tick] || tick;
            """ % Xlabel)
f.circle(x=[1, 2, 3], y=[1, 2, 3])

output_file('test.html')
show(f)

works just fine on Bokeh 0.12.9 - I just added “|| tick” to avoid “undefined”.

Regards,

Eugene

···

On Thursday, October 12, 2017 at 7:28:22 PM UTC+7, Jap Pyck wrote:

I need to assign custom labels stored in a dictionary to
graph axis. The following code used to work before the 0.12.9 release.

Xlabel = {1:‘one’,2:‘two’,3:‘three’}

p.xaxis.formatter =
FuncTickFormatter(code="""

var labels
= %s

return
labels[tick]

“”"
% Xlabel)

Could someone tell me how to adjust the code?

Thank you!

Eugene, thanks a lot for your reply. Your example works fine on my computer. I have realized that my issue is more specific that I thought, maybe related to bkcharts? Here is the example:

from bkcharts import Bar

from bokeh.plotting import figure

from bokeh.io import show, output_file

from bokeh.models import FuncTickFormatter

import pandas as pd

P = {‘col1’:[1,2,3,4,5,6], ‘col2’:[10,5,34,7,22,2]}

Labels ={0:‘zero’,1:‘one’,2:‘two’,3:‘three’,4:‘four’,5:‘five’}

df = pd.DataFrame§

p = figure()

p = Bar(df,legend=None,plot_height = 200,plot_width = 300,values = ‘col2’)

p.xaxis.formatter = FuncTickFormatter(code="""

var labels = %s;

return labels[tick] || tick;

“”" % Labels)

output_file(‘test.html’)

show§

···

On Thursday, October 12, 2017 at 8:02:35 AM UTC-5, [email protected] wrote:

Can you provide a minimal example that doesn’t work for you?

This code:

from [bokeh.io](http://bokeh.io) import show, output_file
from bokeh.models import FuncTickFormatter
from bokeh.plotting import figure

f = figure()
Xlabel = {1: 'one', 2: 'two', 3: 'three'}
f.xaxis.formatter = FuncTickFormatter(code="""
            var labels = %s;
            return labels[tick] || tick;
            """ % Xlabel)
f.circle(x=[1, 2, 3], y=[1, 2, 3])

output_file('test.html')
show(f)

works just fine on Bokeh 0.12.9 - I just added “|| tick” to avoid “undefined”.

Regards,

Eugene

On Thursday, October 12, 2017 at 7:28:22 PM UTC+7, Jap Pyck wrote:

I need to assign custom labels stored in a dictionary to
graph axis. The following code used to work before the 0.12.9 release.

Xlabel = {1:‘one’,2:‘two’,3:‘three’}

p.xaxis.formatter =
FuncTickFormatter(code="""

var labels
= %s

return
labels[tick]

“”"
% Xlabel)

Could someone tell me how to adjust the code?

Thank you!

bkcharts is deprecated and unmaintained. Could you try changing you examples so it uses Bokeh?

Regards,

Eugene

···

On Saturday, October 14, 2017 at 6:09:21 AM UTC+7, Jap Pyck wrote:

On Thursday, October 12, 2017 at 8:02:35 AM UTC-5, [email protected] wrote:

Can you provide a minimal example that doesn’t work for you?

This code:

from [bokeh.io](http://bokeh.io) import show, output_file
from bokeh.models import FuncTickFormatter
from bokeh.plotting import figure

f = figure()
Xlabel = {1: 'one', 2: 'two', 3: 'three'}
f.xaxis.formatter = FuncTickFormatter(code="""
            var labels = %s;
            return labels[tick] || tick;
            """ % Xlabel)
f.circle(x=[1, 2, 3], y=[1, 2, 3])

output_file('test.html')
show(f)

works just fine on Bokeh 0.12.9 - I just added “|| tick” to avoid “undefined”.

Regards,

Eugene

On Thursday, October 12, 2017 at 7:28:22 PM UTC+7, Jap Pyck wrote:

I need to assign custom labels stored in a dictionary to
graph axis. The following code used to work before the 0.12.9 release.

Xlabel = {1:‘one’,2:‘two’,3:‘three’}

p.xaxis.formatter =
FuncTickFormatter(code="""

var labels
= %s

return
labels[tick]

“”"
% Xlabel)

Could someone tell me how to adjust the code?

Thank you!

Eugene, thanks a lot for your reply. Your example works fine on my computer. I have realized that my issue is more specific that I thought, maybe related to bkcharts? Here is the example:

from bkcharts import Bar

from bokeh.plotting import figure

from bokeh.io import show, output_file

from bokeh.models import FuncTickFormatter

import pandas as pd

P = {‘col1’:[1,2,3,4,5,6], ‘col2’:[10,5,34,7,22,2]}

Labels ={0:‘zero’,1:‘one’,2:‘two’,3:‘three’,4:‘four’,5:‘five’}

df = pd.DataFrame§

p = figure()

p = Bar(df,legend=None,plot_height = 200,plot_width = 300,values = ‘col2’)

p.xaxis.formatter = FuncTickFormatter(code="""

var labels = %s;

return labels[tick] || tick;

“”" % Labels)

output_file(‘test.html’)

show§