i got two lists and I am trying to plot the 5 values as a red line and the 0 as a blue line at a fixed y-value. My lists are similar to these two:
main_list = [5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 0, 0, 5, 0, 0]
x_axis = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
I tried to get this output so i could plot each sub-list as a new plot with either the color red for 5 and color blue for 0:
main_list = [[5, 5, 5, 5, 5, 5], [0, 0, 0, 0], [5, 5, 5, 5, 5, 5], [0, 0],[5],[0, 0]]
I have tried the following but I cant seem to get the correct output. I have the feeling that my approach is wrong but I cant think of a different solution.
def split_list(list):
main_list = [[i] for i in list]
for i,sub_list in enumerate(main_list):
if(i<len(main_list)-1):
if(sub_list[0]==main_list[i+1][0]):
main_list[i+1] = sub_list+ main_list[i+1]
del main_list[i]
return main_list
but my output is :
main_list = [[5, 5], [5, 5], [5, 5], [0, 0], [0, 0], [5, 5], [5, 5], [5, 5], [0, 0], [5], [0, 0]]
