Generation

generate functionTue, 21 Mar 2023

Add to this the code for generating a grid on the chart, as well as specifying the percentage difference directly on the chart bars plt.figure(figsize = (12, 4)) plt.bar(data.index, data['nutri'], color = 'darkblue', label = 'nutri') plt.bar(data.index, data['mineral'], color = 'brown', label = 'mineral')

def graph_difference(data, title): difference = data['nutri'] - data['mineral'] percentage = (difference / data['nutri']) * 100 plt.figure(figsize = (12, 4)) plt.bar(data.index, data['nutri'], color = 'darkblue', label = 'nutri') plt.bar(data.index, data['mineral'], color = 'brown', label = 'mineral') plt.title(title, fontsize = 20) plt.grid(axis = 'y') for i in range(len(data)): plt.text(x = data.index[i] - 0.3, y = data['nutri'][i] + 0.1, s = str(round(percentage[i], 1)) + '%', size = 12) plt.show()

Questions about programming?Chat with your personal AI assistant