plotnine is broken with matplotlib==3.6

Viewed 114

I am getting the following error with plotnine==0.9 and matplotlib==3.6.

 File "D:\Python\Python310\lib\site-packages\plotnine\stats\stat_density_2d.py", line 3, in <module>
    import matplotlib._contour as _contour
ModuleNotFoundError: No module named 'matplotlib._contour'

If I downgrade matplotlib==3.5, the problem goes away.

2 Answers

It's discussed here and it's already fixed here Note that it's already merged to main.

It was due to a internal matplotlib call that is no longer supported and has been replaced.

So I guess you could choose between:

  • downgrade to mlp 3.5.3
  • install plotnine@main

till the next plotnine release.

Carlos's answer is correct. However if anybody else, like me, is uncertain of how to install plotnine@main, you can implement the fix rather easily:

  • Find the site_packages folder you python script uses. It usually is a subdirectory of the python version you are using, which can located reliably by trying to reinstall matplotlib or any other package you know you have access to, and checking the logs in the console. ex using python -m pip install matplotlib.

  • Go down into the site_packages/plotnine/stats directory and open up the stats_density_2d.py file in your editor of choice.

  • Apply & save the modifications made in the fix. Alternatively, overwrite the file with the one from the github.

Related