Generation

generate functionTue, 21 Mar 2023

There is a Pandas dataframe: water nutri mineral 0 1 1 2 1 2 2 1 2 3 4 1 3 4 6 3 4 2 5 2 5 4 6 4 6 2 7 2 7 4 5 4 8 5 4 5 9 2 5 4 10 3 6 3 11 4 7 2 12 2 4 3 13 1 3 2 14 3 5 3 15 4 5 1 16 3 6 3 17 2 5 4 18 5 4 5 19 1 3 1 Construct a vertical bar graph comparing these values, where the x-axis is index and the y-axis is the value of each column

import pandas as pd import matplotlib.pyplot as plt data = {'water': [1, 2, 3, 4, 2, 4, 2, 4, 5, 2, 3, 4, 2, 1, 3, 4, 3, 2, 5, 1], 'nutri': [1, 2, 4, 6, 5, 6, 7, 5, 4, 5, 6, 7, 4, 3, 5, 5, 6, 5, 4, 3], 'mineral': [2, 1, 1, 3, 2, 4, 2, 4, 5, 4, 3, 2, 3, 2, 3, 1, 3, 4, 5, 1]} data = pd.DataFrame(data, index = range(20)) plt.figure(figsize = (12, 4)) plt.bar(data.index, data['water'], color = 'r', label = 'water') plt.bar(data.index, data['nutri'], color = 'y', label = 'nutri', bottom = data

Questions about programming?Chat with your personal AI assistant