How to make Pareto Chart in python?

后端 未结 4 1542
野性不改
野性不改 2021-02-01 11:11

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

4条回答
  •  野性不改
    2021-02-01 11:25

    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'.

提交回复
热议问题