6

I'm getting KeyError: 'scale' when I'm trying to run import matplotlib.pyplot

I redownloaded the matplotlib then ran the code but still getting the same error.

I've also opened the new Jupyter notebook and only ran "import matplotlib.pyplot as plt" and I'm still getting the same error. I didn't get any error when I ran "import matplotlib" only.

I would be grateful if you help me out find what's causing the error.

import matplotlib.pyplot as plt
%matplotlib inline

city_pay_top50.plot(kind='bar', x='customer_city', y='payment_value')
plt.title('Cities with top 50 revenues')

plt.show()
KeyError                                  Traceback (most recent call last)
<ipython-input-6-07805b46bb32> in <module>
----> 1 import matplotlib.pyplot as plt
      2 #%matplotlib inline
      3 
      4 plt.bar(city_pay_top50['customer_city'], city_pay_top50['payment_value'])
      5 #city_pay_top50.plot(kind='bar', x='customer_city', y='payment_value')

~/opt/anaconda3/lib/python3.7/site-packages/matplotlib-3.2.1+1847.gfc8a2fa24-py3.7-macosx-10.9-x86_64.egg/matplotlib/pyplot.py in <module>
     41 from matplotlib import docstring
     42 from matplotlib.backend_bases import FigureCanvasBase, MouseButton
---> 43 from matplotlib.figure import Figure, figaspect
     44 from matplotlib.gridspec import GridSpec
     45 from matplotlib import rcParams, rcParamsDefault, get_backend, rcParamsOrig

~/opt/anaconda3/lib/python3.7/site-packages/matplotlib-3.2.1+1847.gfc8a2fa24-py3.7-macosx-10.9-x86_64.egg/matplotlib/figure.py in <module>
     15 
     16 import matplotlib as mpl
---> 17 from matplotlib import docstring, projections
     18 from matplotlib import __version__ as _mpl_version
     19 

~/opt/anaconda3/lib/python3.7/site-packages/matplotlib-3.2.1+1847.gfc8a2fa24-py3.7-macosx-10.9-x86_64.egg/matplotlib/projections/__init__.py in <module>
      2 from .geo import AitoffAxes, HammerAxes, LambertAxes, MollweideAxes
      3 from .polar import PolarAxes
----> 4 from mpl_toolkits.mplot3d import Axes3D
      5 
      6 

~/opt/anaconda3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/__init__.py in <module>
----> 1 from .axes3d import Axes3D

~/opt/anaconda3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/axes3d.py in <module>
     40 
     41 
---> 42 class Axes3D(Axes):
     43     """
     44     3D axes object.

~/opt/anaconda3/lib/python3.7/site-packages/mpl_toolkits/mplot3d/axes3d.py in Axes3D()
     50     def __init__(
     51             self, fig, rect=None, *args,
---> 52             azim=-60, elev=30, zscale=None, sharez=None, proj_type='persp',
     53             **kwargs):
     54         """

~/opt/anaconda3/lib/python3.7/site-packages/matplotlib-3.2.1+1847.gfc8a2fa24-py3.7-macosx-10.9-x86_64.egg/matplotlib/docstring.py in dedent_interpd(func)
     78     """Dedent *func*'s docstring, then interpolate it with ``interpd``."""
     79     func.__doc__ = inspect.getdoc(func)
---> 80     return interpd(func)

~/opt/anaconda3/lib/python3.7/site-packages/matplotlib-3.2.1+1847.gfc8a2fa24-py3.7-macosx-10.9-x86_64.egg/matplotlib/docstring.py in __call__(self, func)
     38     def __call__(self, func):
     39         if func.__doc__:
---> 40             func.__doc__ %= self.params
     41         return func
     42 

KeyError: 'scale'
2
  • I didn't provide the rest of the code because I thought it's unnecessary since they are nothing to do with matploltlib. So is it better to provide the entire code that I wrote? Commented May 18, 2020 at 8:09
  • but I'm still getting the same error when I'm only trying to run "import matplotlib.pyplot" in the new Jupyter notebook without any data or code. Commented May 19, 2020 at 0:04

7 Answers 7

4

For those who may face the same error as me, the problem was solved by updating the version of Jupyter notebook to the latest version in my case.

Sign up to request clarification or add additional context in comments.

Comments

4

It appears to be related to a version mismatch between mpl_toolkits and matplotlib. I couldn’t figure out how to upgrade mpl_toolkits, so I downgraded matplotlib, and the error went away.

pip3 install matplotlib==2.*

Comments

2

I had the same problem. In my case this issue was solved by remove mpl-toolkits in appdata

~/opt/anaconda3/lib/python3.7/site-packages/mpl_toolkits/

It will be helpful remove this file

2 Comments

it worked....lets see if deleting this folder doesn't create any other issue in future.
This works! Can anyone help explain how is this related to the error?
2

Uninstall the old Matplotlib first using the command:

sudo pip3 uninstall matplotlib

Install it again using:

sudo pip3 install matplotlib

Check whether it is working or not. If not working Uninstall twice the matplotlib. Because two version matplotlib may present.

Like this method only, I solved the issue or update the anaconda to update the new version If you are using anaconda.

Hope this may work well.

Comments

1

I met with this problem, too. And the problem is solved by

conda install matplotlib

Hope this working.

Comments

0

In my case, using ipython and matplotlib installed in virtualenv, I had to install python-tk on my Ubuntu 20.04:

sudo apt install python-tk

based on:
https://matplotlib.org/3.1.1/faq/virtualenv_faq.html

Comments

0

I had to pip3 uninstall matplotlib twice since I apparently had 2 versions installed. Then reinstall it.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.