Multiple scatter plots, for elements in list

The code seems to run fine for one entry, but when I loop it in a list im unable to see the plot.

Earlier the code was for just one vin vin = 'bjdcbqj'

I want to display the plot for all elements in the list. Example: vin = ['abdd','ncdnjdc','dkqqw']

    for item in local_vin:
        structs_Final = structs_Full[structs_Full['vin']==item]    

    a_range = [str(i) for i in 
    brake_count = list(MD_Bpressue.value_y)
    BP_colors = len(MDBP_kpa)

     #get the required number of colors 
     BP_mypalette24 = bokeh.palettes.inferno(BP_colors)
     brake_count = list(MD_Bpressue.value_y)
     BP_colors = len(MDBP_kpa)

    #get the required number of colors 
    BP_mypalette24 = bokeh.palettes.inferno(BP_colors)
    BP_colormapper = CategoricalColorMapper(factors=MDBP_kpa, 
    BP_sizes = np.linspace(20, 30, len(MDBP_kpa))

    # Make the ColumnDataSource: source
    BP_source = ColumnDataSource(data={
       'x': MDBP_kpa,
       'y': brake_count,
       'a': a_range
       #,'color' : mypalette24
       ,'size' : BP_sizes

# Save the minimum and maximum values of the gdp column: xmin, xmax
      BP_xmin, BP_xmax = min(MD_Bpressue.value_x)-10, 

# Save the minimum and maximum values of the co2 column: ymin, ymax
     BP_ymin, BP_ymax = min(MD_Bpressue.value_y)-50, 

# Create the figure: plot
    BP_plt = figure(
              plot_height=500, plot_width=500,
              x_range=(BP_xmin, BP_xmax),
              y_range=(BP_ymin, BP_ymax),toolbar_location='right', 
             title="Manual Compound phases – by service brake pedal (DRIVER)")
# Add circle glyphs to the plot
      d = BP_plt.scatter(x='x', y='y', fill_alpha=0.8, source=BP_source, 
               color=dict(field='x', transform=BP_colormapper),

# Create a HoverTool: hover
      BPhover = HoverTool(tooltips=[('kpa','@a'),('brake count','@y')])

# Add the HoverTool to the plot

       ##Format the data to display
       md_cols = ['BreakPressure(kpa)','value_y','parameter_id','reading_id','value_x','_index_'] 

Hi Kamya,

I’m not able to run your code as-is, so it’s difficult to see the outcome you describe. Can you post a simplified, runnable version?

Thank you!

Some sketches / mockups would help greatly as well. It would also help if you edit the post to fix the code formatting. Large code blocks need to be enclosed in triple backtick blocks to format properly. I did this, but the indentation of the code needs to be fixed by you (since you know what it should actually be).

I am not certain but it seems as though you want a single plot with multiple things on it. In which case the general organization of your code should be something like

# create the plot *first*
p = figure(...)

# then loop, adding things to that plot
for thing in things:

    # create a source for one the things to add
    source = ColumnaDataSource(....)

    # add that thing to the plot
    p.line(..., source=source)

# show everything at the end

If all of your data columns are the same length, then they could be potentially put in a single ColumnDataSource that is created up front before the loop, instead of creating separate new CDS instances in the loop. Without knowing anything about the structure of your data, it’s not possible to advise.

Otherwise, I guess I would also suggest some meta-advice, which is: start with something simpler. Often the best way to figure out your actual problem is to factor out smaller “toy” problems first. Once you figure out the mechanics of the sub-parts it can be easier to put everything together to solve your real problem. In this case, say, you could strip away all the bits about colormapping and hover tools and first just figure out how to get the data you have inside a plot (or plots).