Print a bar chart with different dataframes

You could try using the matplotlib bar function. The code is as follows:

carids = [df_1['Carid'].nunique(), df_2['Carid'].nunique(), df_3['Carid'].nunique()]
carname = [df_1['Carname'].nunique(), df_2['Carname'].nunique(), df_3['Carname'].nunique()]
models = [df_1['model'].nunique(), df_2['model'].nunique(), df_3['model'].nunique()]

labels = ["df_1", "df_2", "df_3"]
width = 0.05
x = np.arange(len(labels))

fig, ax = plt.subplots()
rects1 = - width, carids, width, label='Carid')
rects2 =, carname, width, label='Carname')
rects3 = + width, models, width, label='model')

# ax.set_title('')


Here the carids, carname and models are lists with the data that needs to be plotted. The labels are the xtick labels of the graph and you could adjust the width to place the bars appropriately.

The graph obtained is as follows:


CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top