Dynamically add line plots to the graph

Hi,

Can I get some assistance to resolve the following issue:

I need to add line charts dynamically to the one same plot. Number of line charts are unknown. I have this code that works for a single line chart with predefined X and Y values:

   x = x_predefined  # single array of numbers [1, 2, 5, 8, etc.]
   y = y_predefined  # single array of numbers [8, 0, 2, 4, etc.]

   fig = figure(sizing_mode='stretch_both')
   fig.line(x, y, legend_label='Temp.', line_width=2)
   tools = [PanTool(), WheelZoomTool(), ResetTool()]
   fig.tools = tools

   js_resources = INLINE.render_js()
   css_resources = INLINE.render_css()
  
   script, div = components(fig)  # render template

   return render_template('page.html',
                           js_resources=js_resources,
                           css_resources=css_resources)

This function calculates X and Y arrays depending on parameters (a, b, c) and returns dictionary with X and Y values as lists :

def calcs(a, b, c):
    ...
    coordinates = {'X': x_array, 'Y': y_array}
    return coordinates

Let’s say I have three different parameters for each argument of the function calcs(a, b, c). For example a=1, a=3, a=5; b=2, b=6, b=9 and so on for c. Calling the function three times using for loop I get three different dictionaries with X and Y different arrays. So I need to add them to the plot having three different lines on the graph.

I hope I explained my issue clear :slight_smile:

You could leverage MultiLine (MultiLine — Bokeh 2.4.3 Documentation) , then update its datasource by assembling arrays of arrays as calculated for each line.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.