3

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.

Haoran Yi
  • 467
  • 2
  • 11

3 Answers3

3

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.

  • How would one install plotnine@main? – Olivier Sep 24 '22 at 21:11
  • this is another question you could easily search the answer because you will need it. It depends on the env handler/installer you are using. F.e: `pip install https://github.com/user/repo.git@branch` or using poetry `Package B= { git = "git@git.saas.tech/project-a.git", branch = "main" }` – Carlos Vecina Tebar Sep 26 '22 at 12:08
0

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.

Olivier
  • 158
  • 1
  • 11
0

ModuleNotFoundError: No module named 'matplotlib._contour'

Issues with matplotlib 3.6.1 and plotnine 0.9.0

K.I.S.S. in terminal:

pip show matplotlib   #enables you to check version
pip install matplotlib==3.5   #revert and problem is resolved for now.

no more:
ModuleNotFoundError: No module named 'matplotlib._contour'
resolves issue for now that will stop progress...

Kevin
  • 23
  • 4