Pareto is very popular diagarm in Excel and Tableu. In excel we can easily draw a Pareto diagram but I found no easy way to draw the diagram in Python.
I have a pandas d
Another way is using the secondary_y
parameter without using twinx()
:
df['pareto'] = 100 *df.country.cumsum() / df.country.sum()
fig, axes = plt.subplots()
ax1 = df.plot(use_index=True, y='country', kind='bar', ax=axes)
ax2 = df.plot(use_index=True, y='pareto', marker='D', color="C1", kind='line', ax=axes, secondary_y=True)
ax2.set_ylim([0,110])
The parameter use_index=True
is needed because your index
is your x
axis in this case. Otherwise you could've used x='x_Variable'
.