bar chart with Matplotlib

11,977
import matplotlib.pyplot as plt
import pandas as pd

data = {'2013': {1:25,2:81,3:15}, '2014': {1:28, 2:65, 3:75}, '2015': {1:78,2:91,3:86 }}

df = pd.DataFrame(data)

df.plot(kind='bar')

plt.show()

I like pandas because it takes your data without having to do any manipulation to it and plot it.

enter image description here

Share:
11,977
user3430643
Author by

user3430643

Updated on June 09, 2022

Comments

  • user3430643
    user3430643 about 2 years

    Here is my data structure:

    data = {'2013': {1:25,2:81,3:15}, '2014': {1:28, 2:65, 3:75}, '2015': {1:78,2:91,3:86 }}
    

    My x-axis is the number [1,2,3]

    My y-axis is the quantity of each number. For example: In 2013, 1 is x axis while its quantity is 25.

    Print each individual graph for each year

    I would like to graph a bar chart, which uses matplotlib with legend on it.