Matplotlib TypeError: 'NoneType' object is not callable
Asked Answered
C

3

8

I've run this code many times but now it's failing. Matplotlib won't work for any example, even the most trivial. This is the error I'm getting, but I'm not sure what to make of it. I know this is vague and I can't really provide a way to reproduce it. I've uninstalled every package I recently installed and tried reinstalling matplotlib.

fig = plt.figure()
        ax = fig.add_subplot(1, 1, 1)
        plt.plot(self.I_hist)
        plt.show()
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/backends/backend_macosx.py", line 41, in _draw
    self.figure.draw(renderer)
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/artist.py", line 73, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
    return draw(artist, renderer)
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/figure.py", line 2810, in draw
    mimage._draw_list_compositing_images(
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
    return draw(artist, renderer)
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 3020, in draw
    self._unstale_viewLim()
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 776, in _unstale_viewLim
    self.autoscale_view(**{f"scale{name}": scale
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 2932, in autoscale_view
    handle_single_axis(
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 2895, in handle_single_axis
    x0, x1 = locator.nonsingular(x0, x1)
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/ticker.py", line 1654, in nonsingular
    return mtransforms.nonsingular(v0, v1, expander=.05)
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/transforms.py", line 2880, in nonsingular
    if maxabsvalue < (1e6 / tiny) * np.finfo(float).tiny:
  File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/numpy/core/getlimits.py", line 462, in __new__
    dtype = numeric.dtype(type(dtype))
TypeError: 'NoneType' object is not callable
Cockfight answered 27/2, 2022 at 20:42 Comment(11)
Is that the full traceback text? I'm trying to figure out which line of your code it was raised on. Is it the plt.figure() statement?Penitence
Is this error message specific to the script, the virtual environment, the backend? Do you have multiple matplotlib versions installed and it currently points to the wrong version?Oleo
@Penitence yes that's the entire trackback. it is this line: ax = fig.add_subplot(1, 1, 1)Cockfight
@Mr.T it is specific to the venv and this script I believe. I can't seem to find any other versions installed.Cockfight
Found out that it only occurs in debug mode in VSCode, but when ran from the terminal, it works as expected.Cockfight
If it is venv-specific, I wouldn't spend much effort on finding out what the problem is but create a new venv. You want to make it work again, not try to identify the bug.Oleo
I am having the same issue in pycharm using pdbppDeckard
Is there any update on this? Did reinstalling the environment help?Gerger
Same here (PyCharm) when running in Debug mode only. No errors if not using the debugger.Enfeoff
I have the same issue--debug mode only in Pycharm 2022.1Manofwar
Downgrading from Python 3.10 to Python 3.9 made it work. I also have numpy==1.22.3 and matplotlib==3.5.2.Enfeoff
M
8

What version of Python/ Numpy are you using?

I have the same issue with

  • Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32

  • numpy==1.22.3

  • PyCharm 2022.1 (Professional Edition)

>>> from numpy.core import numeric
>>> numeric.dtype(float)

numeric.dtype(float)
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2022.1\plugins\python\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
TypeError: 'NoneType' object is not callable

Apparently numeric.dtype is not defined properly. (Its value is None!) If you use np.dtype(float) that will work.

>>> import numpy as np
>>> np.dtype(float)

dtype('float64')

I believe that if you SHUT OFF scientific mode in PyCharm this should work again.

Settings->Tools->Python Scientific, uncheck Show plots in tool window.

Apparently Jetbrains uses an empty numpy.core template library that breaks the numeric module. (This is an issues thats been raised in bug list but not addressed)

Mismatch answered 22/5, 2022 at 21:51 Comment(2)
I have the same problem, the easiest way is to disable scientific mode as @p-moran mentioned. My pycharm, python and numpy are the same versions.Merca
I am using 2022.2. I disable the scientific and still not workingPollster
S
2

I had this problem only with ipython and pdb. For me, the problem seems to be that pandas.read_csv() changes numpy.core.numeric.dtype to None.

Skier answered 1/3 at 9:48 Comment(2)
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewAtabrine
I think this answer gives more valuable insight to others who are not using IPython. Incomplete, but helpful.Cockiness
C
0

Using python version 3.9, instead of 3.10, worked for me.

As @Bruno said.

Chongchoo answered 6/8 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.