ModuleNotFoundError: No module named 'matplotlib.pyplot'

你。 提交于 2019-12-12 05:14:04

问题


When making a plot, I used both Jupyter Notebook and Pycharm with the same set of code and packages. The code is:

import pandas as pd
import numpy as np 
import matplotlib.pyplot as plt   # as in Pycharm
import matplotlib as plt          # as in Jupyter

df = pd.read_csv("/home/kunal/Downloads/Loan_Prediction/train.csv")
df['ApplicantIncome'].hist(bins=50)
plt.show() #this only in Pycharm not in Jupyter.

In Pycharm, the code works well. But in Jupyter Notebook, it has error:

I wish someone can help me solve this problem


回答1:


You don't need to use %matplotlib inline as other answers here suggest. This is optional and not using it should not prevent importing pyplot.

What should work is the following:

You may decide to use %matplotlib inline in which case you don't have to call plt.show().

You may also use %matplotlib notebook, which gives you an interactive plot.

Finally, you may use %matplotlib tk to get a windowed figure like you would in PyCharm.

All of those options require to have imported matplotlib.pyplot. Importing matplotlib alone is not helpful. Also, if you experience any problems, start a new kernel first (don't try something new in line 27 of your notebook).




回答2:


This is an indication that matplotlib lib/module is not installed. So all you have to do is install this module by running the code below in the cell previous to referring matplotlib:

!pip install matplotlib

Hope it helps!




回答3:


I had the same problem and found a solution! Matplotlib was installed on another python installation I have.

Put the following snippet in a cell and execute it, and you should be good to go:

import sys
!{sys.executable} -m pip install matplotlib



回答4:


add %matplotlib inline on top of your codes,it makes matplotlib execute in interactive way




回答5:


if you are using Anaconda cmd the use command ,conda install matplotlib

If you are using Normal cmd then use command ,pip install matplotlib or pip3 install matplotlib




回答6:


if you are using jupyter notebook in anaconda, matplotlib should be installed to the environment.

go to Environments -> the environment you are using -> change the droplist to not installed -> search matplotlib, and install



来源:https://stackoverflow.com/questions/44149115/modulenotfounderror-no-module-named-matplotlib-pyplot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!