bokeh could not set initial ranges

541 Views Asked by At

I am a begineer in plotting graphs in bokeh. So please forgive me if this is a stupid question.

I am trying to plot a line grpah, where my data is in a dataframe and I have provided the x and y axis as lists. But some of my data in y axis has nonetype objects in it. when it is nonetype in "datapoints" column the corresponding "datapoint_count" has a list like [1]. Otherwise the "dataponts" colums dhould have a list of 20 floats and corresponding datapoint_count column should have a list of 1-20 digits. So basically I want the x axis of the graph to show a range of 1-20y axis should plot the datapoints whichill range between 90.0 - 180.0 When I am running the code there is no python error but if I go to the browser and check developer's tool it says that the bokeh could not set initial ranges.

data=df

random_figure = figure(title='random', x_axis_label="Index", y_axis_label="random [ms]",
                         plot_width=800, plot_height=400, output_backend="webgl")

random_figure.add_tools(random_hover)

id_values = data['testcase_id'].drop_duplicates()

data_temp= data[['id', 'datapoints']].copy()
data_temp['datapoint_count'] = None
data_temp['datapoint_count'] = data_temp['datapoint_count'].astype(object)

for indexes, item in data_temp.iterrows():
    if item['datapoints'] is None or str(item['datapoints']) == '[]': # this has nonetype or strings
        item['datapoints'] = [0]
    else:
        item['datapoints'] = [float(x) for x in item['datapoints'].strip('[').strip(']').split(',')]
    iter_nr = 0
    raw_data_count = []
    for each in item['datapoints']:
        iter_nr += 1
        datapoint_count.append(iter_nr)
    data_temp.at[indexes, 'datapoint_count'] = datapoint_count

name_dict_random = {'name': [], 'legend': [], 'label': []}

logging.info('START OF DRAWINGS')

for ind, id in enumerate(id_values):

    it_color = Turbo256[random.randint(0, 255)]

    name_glyph_random = random_figure.line(x='datapoint_count',
                                               y='datapoints',
                                               line_width=2,
                                               legend_label=str(id),
                                               source=data_temp.where(
                                               data_temp['id'] == id).dropna(),
                                               color=it_color)

    name_dict_random['name'].append(name_glyph_random)
    name_dict_random['label'].append(str(id))

logging.info('AFTER DRAWINGS LOOP')

for label in range(len(data.id.unique())):
    name_dict_random['legend'].append(random_figure.legend.items[label])

initial_value = []
options = list(data.id.unique())
for i, name in enumerate(options):
    options[i] = str(name)

for i in range(len(options)):
    if name_dict_random['label'][i] in initial_value:
        name_dict_random['name'][i].visible = True
        name_dict_random['legend'][i].visible = True
    else:
        name_dict_random['name'][i].visible = False
        name_dict_random['legend'][i].visible = False
1

There are 1 best solutions below

0
On

I have solved it now. Actually though the dataframe showed that the rows content arrays they were actually categorized as objects. Bokeh could not understand what to do with object in the axis. So now I have referred them wih iloc:

x = data[data['id'] == id]['datapoint_count'].iloc[0]
y = data[data['id'] == id]['datapoint'].iloc[0]

            name_glyph_handover = handover_figure.line(x=x, y=y, line_width=2,
                                                       legend_label=str(id), color=it_color)