简体   繁体   English

ModuleNotFoundError:没有名为“matplotlib.pyplot”的模块

[英]ModuleNotFoundError: No module named 'matplotlib.pyplot'

When making a plot, I used both Jupyter Notebook and Pycharm with the same set of code and packages.在制作绘图时,我使用了 Jupyter Notebook 和 Pycharm 以及相同的代码和包。 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.在 Pycharm 中,代码运行良好。 But in Jupyter Notebook, it has error:但是在 Jupyter Notebook 中,它有错误: 在此处输入图片说明

I wish someone can help me solve this problem我希望有人能帮我解决这个问题

This is an indication that matplotlib lib/module is not installed.这表明未安装matplotlib lib/module。 So all you have to do is install this module by running the code below in the cell previous to referring matplotlib:因此,您所要做的就是通过在引用 matplotlib 之前的单元格中运行以下代码来安装此模块:

!pip install matplotlib

Hope it helps!希望有帮助!

I had the same problem and found a solution!我遇到了同样的问题并找到了解决方案! Matplotlib was installed on another python installation I have. Matplotlib 安装在我的另一个 python 安装上。

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

You don't need to use %matplotlib inline as other answers here suggest.您不需要像这里的其他答案建议的那样使用%matplotlib inline This is optional and not using it should not prevent importing pyplot.这是可选的,不使用它不应该阻止导入 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() .您可以决定使用%matplotlib inline在这种情况下您不必调用plt.show()

在此处输入图片说明

You may also use %matplotlib notebook , which gives you an interactive plot.您也可以使用%matplotlib notebook ,它为您提供交互式绘图。

在此处输入图片说明

Finally, you may use %matplotlib tk to get a windowed figure like you would in PyCharm.最后,您可以像在 PyCharm 中一样使用%matplotlib tk来获取窗口图形。

在此处输入图片说明

All of those options require to have imported matplotlib.pyplot .所有这些选项都需要导入matplotlib.pyplot Importing matplotlib alone is not helpful.单独导入matplotlib没有帮助。 Also, if you experience any problems, start a new kernel first (don't try something new in line 27 of your notebook).此外,如果您遇到任何问题,请先启动一个新内核(不要在笔记本的第 27 行尝试新的东西)。

if you are using jupyter notebook in anaconda, matplotlib should be installed to the environment.如果您在 anaconda 中使用 jupyter notebook,则应将 matplotlib 安装到环境中。

go to Environments -> the environment you are using -> change the droplist to not installed -> search matplotlib, and install转到环境 -> 您正在使用的环境 -> 将下拉列表更改为未安装 -> 搜索 matplotlib,然后安装

if you are using Anaconda CMD the use this command,如果您使用的是 Anaconda CMD,请使用此命令,

conda install matplotlib 

If you are using Normal CMD then use command,如果您使用的是普通 CMD,则使用命令,

pip install matplotlib

or

pip3 install matplotlib

在代码顶部%matplotlib inline添加%matplotlib inline ,它使 matplotlib 以交互方式执行

这段代码对我有用

%pip install matplotlib-inline

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 问:ModuleNotFoundError:没有名为“ matplotlib.pyplot”的模块,等等 - Q: ModuleNotFoundError: No module named 'matplotlib.pyplot', etc 导入错误:没有名为 matplotlib.pyplot 的模块 - ImportError: No module named matplotlib.pyplot 将 matplotlib.pyplot 作为 plt 导入时出现问题(ModuleNotFoundError: No module named 'PIL') - Having problems with importing matplotlib.pyplot as plt (ModuleNotFoundError: No module named 'PIL') 来自matplotlib.pyplot import plt ImportError:没有名为'matplotlib'的模块 - from matplotlib.pyplot import plt ImportError: No module named 'matplotlib' 当我尝试运行“import matplotlib.pyplot as plt”时,我收到以下错误:“ModuleNotFoundError: No module named 'PIL'” - When I try to run “import matplotlib.pyplot as plt”, I receive the following error: “ModuleNotFoundError: No module named 'PIL'” 代码未找到matplotlib.pyplot模块 - Code is not finding the matplotlib.pyplot module 模块“matplotlib.pyplot”没有属性“xaxis” - module 'matplotlib.pyplot' has no attribute 'xaxis' 模块 'matplotlib.pyplot' 没有属性 'patches' - module 'matplotlib.pyplot' has no attribute 'patches' 模块“matplotlib.pyplot”没有属性“yaxis” - module 'matplotlib.pyplot' has no attribute 'yaxis' 当我使用matplotlib.pyplot时,在Python 3.6中没有名为PyQt4的模块 - No module named PyQt4 in python 3.6 when I use matplotlib.pyplot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM