0

Somehow I am not able to display values on bar chart.. I want to put the Means (CTEs = [aluminum_mean, copper_mean, steel_mean]) to the bar charts. aluminium_mean -> bar chart 1..

I tried it with enumerate but it does not work.

.

aluminum = np.array([93.75,100,81.25,87.5,87.5])
copper = np.array([87.5, 83.75, 87.5, 93.75, 81.25 ])
steel = np.array([100, 93.75, 87.5, 93.75, 93.75])

# Calculate the average
aluminum_mean = np.mean(aluminum)
copper_mean = np.mean(copper)
steel_mean = np.mean(steel)

# Calculate the standard deviation
aluminum_std = np.std(aluminum)
copper_std = np.std(copper)
steel_std = np.std(steel)

# Create lists for the plot
materials = ['Model 1', 'Model 2', 'Model 3']
x_pos = np.arange(len(materials))
CTEs = [aluminum_mean, copper_mean, steel_mean]
error = [aluminum_std, copper_std, steel_std]

# Build the plot
fig, ax = plt.subplots()
ax.bar(x_pos, CTEs, yerr=error, align='center', alpha=1, color = 'white', edgecolor='black', capsize=10, width = 0.35)
ax.set_ylabel('Accuracy in %', fontweight='bold')
ax.set_xlabel('Feature set', labelpad=20, fontweight='bold')

ax.set_xticks(x_pos)
ax.set_xticklabels(materials)
ax.set_title('Comparison data input')

#Legende
red_patch = mpatches.Patch(color='white', label='Model 1: 3')
blue_patch = mpatches.Patch(color='white', label='Model 2: 2')
blue1_patch = mpatches.Patch(color='white', label='Model 3: 1')

#plt.legend(handles=[red_patch, blue_patch], bbox_to_anchor=(1, 0.5))
plt.legend(handles=[red_patch, blue_patch, blue1_patch], bbox_to_anchor=(1, 0.5))

plt.figure(figsize=(20,20))
  • is this what you are looking for? https://matplotlib.org/3.1.1/gallery/lines_bars_and_markers/barchart.html#sphx-glr-gallery-lines-bars-and-markers-barchart-py – Roberto Dec 29 '20 at 10:04
  • In princible, yes :) Either inside the bar or outside. – newbie03 Dec 29 '20 at 10:08

0 Answers0