pythonpareto-chart

Python Pareto Chart issue


Trying to get a pareto-chart in Python following

I am following this code in my Jupyter notebook How to make Pareto Chart in python?

I'm not getting the pareto increasing uniformly, instead its zigzag and the x-labels are sorted alphabetically, instead of ordered by country though the df.sort_values is there.

Please suggest what could be the issue.

Python-Pareto-Issue


Solution

  • It seems that matplotlib (aka plt) forces the alphetical sort for old versions of matplotlib (when did you last uprade it ?). You can see more informations and a great answer on solutions and workarounds here : How to prevent alphabetical sorting for python bars with matplotlib? In particular, just set a numerical index :

    df['Nation'] = ['USA', 'Canada', 'Russia', 'UK', 'Belgium', 'Mexico', 'Germany', 'Denmark']
    

    Then df.index will keep numerical order.