Matplotlib TypeError: NoneType object is not callable

2024/10/4 3:31:38

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 _drawself.figure.draw(renderer)File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/artist.py", line 73, in draw_wrapperresult = draw(artist, renderer, *args, **kwargs)File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/artist.py", line 50, in draw_wrapperreturn draw(artist, renderer)File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/figure.py", line 2810, in drawmimage._draw_list_compositing_images(File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_imagesa.draw(renderer)File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/artist.py", line 50, in draw_wrapperreturn draw(artist, renderer)File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 3020, in drawself._unstale_viewLim()File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 776, in _unstale_viewLimself.autoscale_view(**{f"scale{name}": scaleFile "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 2932, in autoscale_viewhandle_single_axis(File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 2895, in handle_single_axisx0, x1 = locator.nonsingular(x0, x1)File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/ticker.py", line 1654, in nonsingularreturn mtransforms.nonsingular(v0, v1, expander=.05)File "/Users/username/Documents/Newsvendor/venv/lib/python3.10/site-packages/matplotlib/transforms.py", line 2880, in nonsingularif 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
Answer

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 Execexec(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)

https://en.xdnf.cn/q/70652.html

Related Q&A

Resize image faster in OpenCV Python

I have a lot of image files in a folder (5M+). These images are of different sizes. I want to resize these images to 128x128. I used the following function in a loop to resize in Python using OpenCVdef…

How to install Yandex CatBoost on Anaconda x64?

Iv successfully installed CatBoost via pip install catboostBut Iv got errors, when I tried sample python script in Jupiter Notebookimport numpy as np from catboost import CatBoostClassifierImportError:…

pyspark returns a no module named error for a custom module

I would like to import a .py file that contains some modules. I have saved the files init.py and util_func.py under this folder:/usr/local/lib/python3.4/site-packages/myutilThe util_func.py contains al…

Perform a conditional operation on a pandas column

I know that this should be simple, but I want to take a column from a pandas dataframe, and for only the entries which meet some condition (say less than 1), multiply by a scalar (say 2).For example, i…

How to programmatically get SVN revision number?

Like this question, but without the need to actually query the SVN server. This is a web-based project, so I figure Ill just use the repository as the public view (unless someone can advise me why this…

Convert fractional years to a real date in Python

How do I convert fractional years to a real date by using Python? E. g. I have an array [2012.343, 2012.444, 2012.509] containing fractional years and I would like to get "yyyy-mm-dd hh:mm".

Django template: Translate include with variable

I have a template in which you can pass a text variable. I want to include this template into another one but with a translated text as its variable. How can you achieve this?I would like something li…

Pandas - Creating a New Column

I have always made new columns in pandas using the following:df[new_column] = valueI am using this method, however, am receiving the warning for setting a copy.What is the way to make a new column with…

Adding an extra column to (big) SQLite database from Pandas dataframe

I feel like Im overlooking something really simple, but I cant make it work. Im using SQLite now, but a solution in SQLAlchemy would also be very helpful.Lets create our original dataset:### This is ju…

error inserting values to db with psycopg2 module [duplicate]

This question already has answers here:psycopg2: cant adapt type numpy.int64(4 answers)Inserting records into postgreSQL database in Python(3 answers)Closed 3 months ago.I am attempting to insert a dat…