I would like to create a barchart in matplotlib with 3 bars for each of 12 weeks. I adopted a code for barcharts with two bars but unfortunately I get the following error message: "ValueError: shape mismatch: objects cannot be broadcast to a single shape "
Here is my code:
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
labels = ['Woche \n 1', 'Woche \n 5', 'Woche \n 6', 'Woche \n 8', 'Woche \n 8' , 'Woche \n 11', 'Woche \n 12',
'Woche \n 41', 'Woche \n 43', 'Woche \n 46', 'Woche \n 48', 'Woche \n 49', 'Woche \n 50']
conventional = [1063, 520, 655, 47, 1516, 3200, 1618, 1378, 577, 504, 76, 1154]
IC = [345, 217, 229, 0, 800, 2700 ,1253, 896, 151, 382, 4, 797 ]
CO = [100, 130, 80, 0, 580, 2450, 1020, 650, 0, 300, 0, 600 ]
x = np.arange(len(labels)) # the label locations
width = 0.30 # the width of the bars
fig, ax = plt.subplots(figsize=(13,8), dpi=100)
rects1 = ax.bar(x - width/2, conventional, width, label='conventional')
rects2 = ax.bar(x + width/2, IC, width, label='IC')
rects3 = ax.bar(x + width/2, CO, width, label='CO')
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Surplus', fontsize = 17)
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.tick_params(axis='both', which='major', labelsize=16)
ax.legend(loc='center left', bbox_to_anchor=(0.07, 1.04), fontsize = 16, ncol=3)
fig.tight_layout()
plt.savefig('PaperA_Results_7kWp.png', edgecolor='black', dpi=400, bbox_inches='tight')
plt.show()
Can anyone tell me, what causes the error? I'd appreciate every comment.
