Stack Exchange
connect "caps" of box plot
hello i have a python function to connect the "caps" of 2 boxplots, but i can't conect only the superior caps, and that's what I need(only connect it the superior caps with the pink line), i very appreciate a lot you help,
my code is the next
def set_boxes_lim_max_line(bp, w, c):
    limit_sup_x = []
    limit_sup_y = []

    for p in bp['caps']:
        data = p.get_data()
        #x=bp['caps'][1].get_data()[0]
        x=np.max([data[0].mean(),data[0].mean()])
        #x=bp['boxes'][0].get_data()[0]
        y = data[1].max()
        limit_sup_x.append(x)
        limit_sup_y.append(y)

    plt.plot(limit_sup_x,limit_sup_y, color = c, linewidth = w)
    #plt.plot(limit_sup_x, color = c, linewidth = w)


the function that calls it:
 bp1 = plt.boxplot([sample1[i] for i in posiciones2], positions = (range(1, 3)), widths = 0.6)
    set_box_color(bp1,'red')

    # Agregar lineas caja roja
    set_boxes_lim_max_line(bp1,1.2,'hotpink')#LINEA LIMITE SUPERIOR
    set_boxes_q_min_line(bp1, 1.2, 'tomato') #LINEA "Q3" SUPERIOR CAJA    
    set_boxes_median_line(bp1, 1.2, 'seagreen')#LINEA MEDIANA
    set_boxes_q_max_line(bp1, 1.2, 'darkred')#LINEA "Q1" INFERIOR CAJA
    #set_boxes_q_min_line(bp1, 1.2, 'tomato') #LINEA LIMITE INFERIOR


Can you post the code that calls the function set_boxes_lim_max_line()?

i have already post it,thanks in advance

This will do it:
def set_boxes_lim_max_line(bp, w, c):
    limit_sup_x = []
    limit_sup_y = []

    for p in bp['caps'][1::2]:
        data = p.get_data()
        #x=bp['caps'][1].get_data()[0]
        x=np.max([data[0].mean(),data[0].mean()])
        #x=bp['boxes'][0].get_data()[0]
        y = data[1].max()
        limit_sup_x.append(x)
        limit_sup_y.append(y)

    plt.plot(limit_sup_x,limit_sup_y, color = c, linewidth = w)

Example:  

