How to plot multiple horizontal bar charts in the same graph using cufflinks library

716 Views Asked by At

I want to plot a graph having two or more different horizontal bar charts in it using cufflinks library ( i.e. ipolt()). I have separately plotted both the bar charts using cufflinks library but now want to combine in one graph.

This is my code snippet :

params_systems = {
    'kind': 'barh',
    'yTitle': '',
    'xTitle': '',
    'title': '',
    'margin': dict(l=70)
}

a=req_df.groupby(['System'])['System'].count().iplot(**params_systems)

b=dbrs_df.groupby(['System'])['System'].count().iplot(**params_systems)

This code provides me two separate bar charts.

I tried the below code too, but then it is plotting both the charts in a stack mode. I dnt want both the bar charts to be stacked.

import pandas as pd
DF1 = pd.concat([a,b])
DF1.iplot(**params_systems)

What should i do? I want to do this task using cufflinks library only. I would appreciate any help and suggestions.

1

There are 1 best solutions below

0
Dreamgonfly On

Try the code below. I slightly changed your code and this will work.

DF1 = pd.concat([a,b], axis=1)
DF1.iplot(**params_systems)

The problem was that you concatenated two series in the wrong way. The default behavior of pd.concat is to append one series to the bottom of the other, which results in a long series. By changing the axis parameter, you can put the two series next to each other. This way cufflinks knows how to plot the two kinds of data nicely.