Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib TypeError: 'NoneType' object is not callable

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
like image 336
ChessGuy Avatar asked Jun 23 '26 09:06

ChessGuy


1 Answers

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)

like image 89
P Moran Avatar answered Jun 24 '26 21:06

P Moran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!