简体   繁体   中英

when importing matplotlib in Jupyter Notebook no subpackages found

I'm trying to import matplotlib.pyplot (ver 3.2.1) in Jupyter Notebook but keep getting an error.
It might be worth mentioning that I have ArcGIS on my laptop where there is Python 2.7 and Matplotlib of version 1, not 3. And steps listed below work fine in PyCharm.

import matplotlib.pyplot as plt

ModuleNotFoundError: No module named 'matplotlib.pyplot

I tried uninstalling the whole thing with running pip uninstall matplotlib from command line (using Windows) and install it then back, but it also doesn't seem to have any effect.

Just importing matplotlib works fine until I run some code that includes its functions. Then errors arise, ie

import matplotlib

This cell runs with no errors. Then I try to display some basic stuff:

x = [0, 1, 2, 3, 4]
y = [2, 2, 2, 2, 2]
df = pd.DataFrame([x,y], columns=['a','b','c','d','f'])
df['b'].hist()
matplolib.pyplot.show() 

and get multiple traceback outputs

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in _get_plot_backend(backend)
   1599         # Because matplotlib is an optional dependency and first-party backend,
   1600         # we need to attempt an import here to raise an ImportError if needed.
-> 1601         import pandas.plotting._matplotlib as module
   1602 
   1603         _backends["matplotlib"] = module

ModuleNotFoundError: No module named 'matplotlib.artist'

I also tried this:

%matplotlib
import matplotlib.pyplot as plt

Which resulted in yet another error:

~\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in find_gui_and_backend(gui, gui_select)
    286         # overwritten that.
    287         # WARNING: this assumes matplotlib 1.1 or newer!!
--> 288         backend = matplotlib.rcParamsOrig['backend']
    289         # In this case, we need to find what the appropriate gui selection call
    290         # should be for IPython, so we can activate inputhook accordingly

AttributeError: module 'matplotlib' has no attribute 'rcParamsOrig'

Help me please to resolve this issue.

Try to reinstall the module as follows. A broken installation could lead to this error.

pip install --upgrade --force-reinstall matplotlib 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM