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 = ax.bar(x - width, carids, width, label='Carid')
rects2 = ax.bar(x, carname, width, label='Carname')
rects3 = ax.bar(x + width, models, width, label='model')
ax.set_ylabel('Count')
# ax.set_title('')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.legend()
fig.tight_layout()
plt.show()
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.