Боке: выберите ось x для отображения на графике (не числа)

У меня есть такой сюжет:

from bokeh.io import output_file, show
from bokeh.charts import Line
from bokeh.models import FixedTicker
import pandas as pd

output_file('file.html')
data = {'Date shift end': {0: '01/01/16', 1: '01/02/16', 2: '01/03/16',
                           3: '01/04/16', 4: '01/05/16', 5: '01/06/16',
                           6: '01/07/16', 7: '01/08/16', 8: '01/09/16',
                           9: '01/10/16', 10: '01/11/16', 11: '01/12/16',
                           12: '01/13/16', 13: '01/14/16', 14: '01/15/16',
                           15: '01/16/16', 16: '01/17/16', 17: '01/18/16',
                           18: '01/19/16', 19: '01/20/16'},
        'Finance_Lbs': {0: 0.0, 1: 92218.080000000002, 2: 469434.14000000001,
                        3: 513948.95000000001, 4: 578014.71999999997,
                        5: 432396.69, 6: 573912.75,
                        7: 519266.57000000001, 8: 586680.66000000003,
                        9: 561292.56999999995, 10: 459121.15000000002,
                        11: 364463.34999999998, 12: 560154.51000000001,
                        13: 473212.65999999997, 14: 576373.17000000004,
                        15: 587393.56999999995, 16: 585796.46999999997,
                        17: 553028.40000000002, 18: 541770.03000000003,
                        19: 534533.95999999996}}
data = pd.DataFrame(data)
plot = Line(data, 'Date shift end', 'Finance_Lbs', title='FG Lbs',
            xlabel='Date', ylabel='Production Lbs', width=1000)
show(plot) 

введите здесь описание изображения

Мне нужен этот график со всеми его точками, но показывать только определенные тики по оси x::

['01/01/16', '01/05/16', '01/10/16', '01/15/16', '01/20/16']

С FixedTicker я получаю эту ошибку::

>>> plot.xaxis[0].ticker=FixedTicker(ticks=['01/01/16', '01/05/16',
                                            '01/10/16', '01/15/16'])
Error: expected an element of Seq(Float), got seq with invalid items
>>>

Я могу использовать только целые числа для ticks::

>>> plot.xaxis[0].ticker=FixedTicker(ticks=[0, 5, 10, 15])

Но у меня есть числа вместо «дат» в формате str


person Náthali    schedule 16.11.2016    source источник
comment
Использование p.xaxis.formatter после FixedTicker, как здесь 40469619#40469619" title="могу ли я изменить бегущие строки на графике на пользовательские текстовые бегущие строки"> stackoverflow.com/questions/40453228/ позволяют поместить нужный текст   -  person user3313834    schedule 18.11.2016


Ответы (1)


from bokeh.io import output_file, show
from bokeh.charts import Line
from bokeh.models import FixedTicker
from bokeh.models import FuncTickFormatter, FixedTicker
import json
import pandas as pd

output_file('file.html')
data = {'Date shift end': {0: '01/01/16', 1: '01/02/16', 2: '01/03/16',
                           3: '01/04/16', 4: '01/05/16', 5: '01/06/16',
                           6: '01/07/16', 7: '01/08/16', 8: '01/09/16',
                           9: '01/10/16', 10: '01/11/16', 11: '01/12/16',
                           12: '01/13/16', 13: '01/14/16', 14: '01/15/16',
                           15: '01/16/16', 16: '01/17/16', 17: '01/18/16',
                           18: '01/19/16', 19: '01/20/16'},
        'Finance_Lbs': {0: 0.0, 1: 92218.080000000002, 2: 469434.14000000001,
                        3: 513948.95000000001, 4: 578014.71999999997,
                        5: 432396.69, 6: 573912.75,
                        7: 519266.57000000001, 8: 586680.66000000003,
                        9: 561292.56999999995, 10: 459121.15000000002,
                        11: 364463.34999999998, 12: 560154.51000000001,
                        13: 473212.65999999997, 14: 576373.17000000004,
                        15: 587393.56999999995, 16: 585796.46999999997,
                        17: 553028.40000000002, [![enter image description here][1]][1]18: 541770.03000000003,
                        19: 534533.95999999996}}
data = pd.DataFrame(data)
dicaxis = data['Date shift end'].to_dict()
paxis = len(data)/5
select_axis_key = range(0, len(data), paxis)
select_axis = {k:v for (k,v) in dicaxis.items() if k in select_axis_key}

plot = Line(data, 'Date shift end', 'Finance_Lbs', title='FG Lbs',
            xlabel='Date', ylabel='Production Lbs', width=1000)
mapp = """ var mapping = {};
       return mapping[tick]; """
plot.xaxis.ticker = FixedTicker(ticks=select_axis_key)
plot.axis.formatter = FuncTickFormatter(code=mapp.format(json.dumps(select_axis)))
show(plot)

Сюжет боке

person Náthali    schedule 18.11.2016