Home > Software engineering >  Clustered Column Line with Mathplotlib
Clustered Column Line with Mathplotlib

Time:07-30

I am trying to make a Clustered Column Line with Mathplotlib. Below you can see data

import pandas as pd
import numpy as np
pd.set_option('max_columns', None)
import matplotlib.pyplot as plt 
    
  
data = {
         'year':[2005,2006,2007,2008,2009,2010,2011,2012,2013,2014],
          'open':[70,20,24,150,80,90,60,90,20,20],
         'closed':[30,14,20,10,20,40,10,10,10,10],
        }

df = pd.DataFrame(data, columns = [
                                   'year',
                                   'open',
                                   'closed',
                                   ])

Now I want to plot chart as the chart shown below:

enter image description here

I tried with those lines below but is not working, because I plotted only bars without line.

df.plot(x='year', kind='bar', title='Comparison',legend=True,ylabel='open',xlabel='')
plt.grid()
plt.legend(loc='upper left', shadow=True)

So can anybody help me how to solve this problem and make plot same as the plot from the picture above?

CodePudding user response:

You have to use two different y axis, one for the barplot and the other for the line, with enter image description here

CodePudding user response:

Using enter image description here

  • Related