Cannot import name 'artist' from 'matplotlib' (Python) - python

I recently updated matplotlib and now I am consistently getting an error when I write from matplotlib import pyplot as plt.
ImportError: cannot import name 'artist' from 'matplotlib' (C:\Users\nenze\AppData\Roaming\Python\Python39\site-packages\matplotlib\__init__.py)
I've tried uninstalling and reinstalling matplotlib which didn't solve anything. I even tried to downgrade to an older version but I am still getting the same error.
This is with matplotlib version 3.5.1. This is with Python version 3.9.7. This is through Jupyter Notebooks.

Ended up deleting Python\Python39\site-packages\matplotlib_init_.py and it worked itself out.
I also deleted files that started with ~ (ex: ~matplotlib).

Related

Why am I getting error message as "ModuleNotFoundError: No module named 'plotly.express" while it was working before?

I'm having this bizarre experience; I'm re-running a code to plot a geographical graph using Plotly and use
import plotly.express as px
but it gives me the error message saying that "ModuleNotFoundError: No module named 'plotly.express'".
I can confirm that plotly is installed, and most importantly it was working until last night.
How come its suddenly not finding the module name while it was working until last night?
Has something been changed?
Any feedback much appreciated.
Apparently, it turned out that upgrading plotly version solved the problem.
To upgrade plotly, I simply run the following codes to check the plotly version.
import plotly
plotly.__version__
That gave me the output of version of plotly as '5.11.0'. Then I upgraded the plotly version to '5.11.0' by writing the following code:
pip install plotly==5.11.0

Python throws module has no attibute error

I have a Python program that has the following import command:
import matplotlib.pyplot as plt
and on line:
ax.imshow(worldmap, cmap=plt.cm.cmapname)
throws the following error:
<module>
ax.imshow(worldmap, cmap=plt.cm.cmapname)
AttributeError: module 'matplotlib.cm' has no attribute 'cmapname'
The matplotlib library was installed with pip install matplotlib.
Strangely, this same program runs on another person's PC with no problem, and he has never seen this error before. Would anyone know what is causing this error and how to fix it?
I'm running Python 3.9.1. I'm wondering if we might be using different versions of matplotlib and whether this might be an issue.
Ali Irani had the right answer. I was using Python 3.9.5 with matplotlib 3.4.2, and my friend was using Python 3.7.1 with matplotlib 3.0.3. I installed what my friend was using, and his code worked. By the way: I first tried installing matplotlib with Python 3.9.5, and it wouldn't install. It seems that successive matplotlib versions are not upwardly compatible. Really, you would expect that whatever worked with older versions should also work with newer versions, but this evidently is not the case.

Module 'matplotlib' has no attribute 'colors' error

Good afternoon,
I am running Python 3.9.2 on my Mac (Mac OS Big Sur 11.2.3), and when running my code, that includes:
import matplotlib.pylab as plt
(...)
cm = plt.get_cmap('viridis')
cNorm = plt.colors.Normalize(vmin=min(forces), vmax=max(forces))
scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=cm)
I get the error:
cNorm = plt.colors.Normalize(vmin=min(forces), vmax=max(forces))
AttributeError: module 'matplotlib.pylab' has no attribute 'colors'
I have tried uninstalling and installing matplotlib (both with conda and pip), and that didn't work. I tried installing different versions of matplotlib, and that didn't work either. I looked at this thread but it didn't answer my questions.
I don't understand what the issue is here, since the code was provided by my instructor, and since the error is for the second use of plt, the error is not with the import of matplotlib.
Please let me know if you know what the issue is, or what I could try to fix this. Thank you.

matplotlib.pyplot giving error 'ImportError: No module named Tkinter' on python 2.7

I'm using a remote machine for computation and data analysis. I don't have sudo access in this machine, for data analysis purposes I want to use python libraries such as vtk etc since pip is not installed in this machine, I set up a 'virtual-environment' and install VTK there,
I used the method explained here (https://stackoverflow.com/a/13958308/10755782). Then I could install vtk in the virtual environment using pip.
But now the problem is that I can't import matplotlib.pyplot, it is giving me the error
ImportError: No module named Tkinter.
This error is strange because matplotlib.pyplot works in this particular system outside my virtual-environment. There are a few workarounds to start using matplotlib.pyplot without tkinter such as this (https://stackoverflow.com/a/49988926/10755782), but this is not helpfull in my case as this machine is remote-accessed and I need 'tkinter' to view the graphs on my screen.
I tried installing 'tkinter' inside my virtual-env, but I could not ( since we can't install 'tkinter' with pip and I don't have sudo access).
As I could not find any immediate solution to this problem anywhere I tried to fix this myself and I did the following,
inside my virtual environment, the version of matplotlib was 2.2.4 and outside it was 1.2.0 ( which is working fine). So I downgraded the version of matplotlib inside my virtual environment to 1.2.0
pip install 'matplotlib==1.2.0' --force-reinstall
now I have the same version of matplotlib inside and outside the virtual env. But now, when I try import matplotlilb.pyplot as plt I'm getting the error
ImportError: /b/home/ipcms/rcheenik/Python_virt-env/python2.7/my_new_env/lib/python2.7/site-
packages/matplotlib/_cntr.so: undefined symbol: _intel_fast_memset
Is there any way to fix this ^^ error? any of these following will be able to help me.
without OR is there any way to install tkinter without sudo ? or inside the 'virtual-environment' ?
OR is there any alternatives to matplotlib.pyplot which works without 'tkinter' and still display graphs remotely? ( not favourable, as I have to rewrite the entire code )
Thanks in advance for the help.
I found this answer to a similar question however, which I believe would solve your issue.
https://stackoverflow.com/a/49988926/8775307
It imports matplotlib.pyplot without tkinter. I don't know if all the features are actually included though, so you'll have to test and let us know :).
You could always write to the administrator and request Tkinter - it's a widely used and useful package, so they might be willing to include it.

python: ImportError: No module named patheffects

When i try to run a python script in which i do an import statement matplotlib.patheffects, i get an error message saying there is no module called patheffects.
the statement is
import matplotlib.patheffects
Kindly help me to figure out the reason for this error and how to make the code run without this glitch.
import matplotlib.patheffects works perfectly well for me. Please make sure you have matplotlib installed. The most current version is 1.0.1. You can download from here.
Matplotlib depends on numpy, so make sure you have it installed before installing matplotlib.
Also check out the tips on installing matplotlib.

Categories

Resources