[Python] Pyplot Printing All Bars Overlapping in First Position in Grouped Bar Chart

Discussão em 'Python' iniciado por Stack, Setembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I'm generating a grouped bar chart showing what orders are ordered to arrive on what day of the week. My code is as follows:

    plt.figure(1)
    x = np.arange(7)
    width = .1
    for j in range(9):
    print(pdChart[j])
    plt.bar((j-4)/10, pdChart[j], width, label=list(flavors.keys())[j])

    plt.xticks(x,daysOWeek)
    plt.ylabel("Orders")
    plt.legend()
    plt.title("Preferred Delivery Days")
    plt.show()


    However, it's printing everything in the Monday position. So the output is only "Monday" data with the highest day's total appearing as the bar height for each flavor. The individual bars are aligned properly and all that. But there's nothing for Tuesday, Wednesday, etc.

    [420 352 425 391 423 388 387]
    [0 0 0 0 0 0 0]
    [857 840 881 900 852 851 874]
    [248 234 246 239 242 223 249]
    [235 243 227 249 270 251 249]
    [1670 1822 1835 1818 1796 1804 1764]
    [427 461 430 490 428 435 444]
    [102 101 94 86 102 110 107]
    [718 743 718 705 741 781 716]


    So the data is right. But instead of seven bars per line, I get one that's 425, 0, 900, 249, etc. only appearing to show the highest day total for the week, which is why I assume it's overlapping.

    Continue reading...

Compartilhe esta Página