本文介绍了ModuleNotFoundError:没有名为"matplotlib.pyplot"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

进行绘图时,我同时使用了Jupyter Notebook和Pycharm,并使用了相同的代码和软件包.代码是:

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.

在Pycharm中,代码运行良好.但是在Jupyter Notebook中,它有错误:

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

我希望有人能帮助我解决这个问题

I wish someone can help me solve this problem

推荐答案

您无需使用%matplotlib inline作为此处的其他答案.这是可选的,不使用它不会阻止导入pyplot.

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.

以下是可行的方法:

您可以决定使用%matplotlib inline,在这种情况下,您不必致电plt.show().

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

您还可以使用%matplotlib notebook,它可以为您提供交互式绘图.

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

最后,您可以像在PyCharm中一样使用%matplotlib tk来获得窗口化的图形.

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

所有这些选项都需要导入matplotlib.pyplot.单独导入matplotlib并没有帮助.另外,如果遇到任何问题,请先启动一个新内核(不要在笔记本的第27行尝试新的东西).

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).

这篇关于ModuleNotFoundError:没有名为"matplotlib.pyplot"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:18