I'm trying to run the contourf example from the matplotlib documentation.
When I run it from a python shell, everything works well, but when I run it as a script (python contourf_demo.py), the following error rises:
Traceback (most recent call last):
File "matplotlib.py", line 3, in
import matplotlib.pyplot as plt
File "/home/user/dir/contourf_demo.py", line 3, in
import matplotlib.pyplot as plt
ImportError: No module named pyplot
I'm using Ubuntu 12.04, and the problem comes when importing:
import matplotlib.pyplot as plt
I have tried using different ways to call the import (such as from matplotlib import pyplot), but it doesn't work neither.
You can't import a module named XYZ from a file called XYZ.py, because Python would interpret that you are trying to import the file itself.
Change your file from matplotlib.py to anything else.
Related
I have been trying to plot a certain signal on python but it keeps giving me an error message I don't know how to solve it
from matplotlib import pyplot as plt
from matplotlib import style
import mysignals as Sig
style.use('ggplot')
style.use('dark_background')
f,pltr_arr=plt.subplots(3,sharex=True)
pltr_arr[0].plot(sig.lnputSignal_1KHz_15kHz,color='magenta')
pltr_arr[0].set_title('subplot 1',color='magenta')
pltr_arr[1].plot(sig.InputSignal_1kHz_15kHz,color='yellow')
pltr_arr[1].set_title('Subplot 1', color='yellow')
pltr_arr[2].plot(sig.InputSignal_1kHz_15lkHz,color='green')
pltr_arr[2].set_title('Subplot 1',color='green')
above is the code of what I tried and below is the error message
ModuleNotFoundError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_9776\3731026071.py in
1 from matplotlib import pyplot as plt
2 from matplotlib import style
----> 3 import mysignals as Sig
4
5 style.use('ggplot')
ModuleNotFoundError: No module named 'mysignals'
Your error is ModuleNotFoundError: No module named 'mysignals'.
This error occurred since there is no python module named mysignals.py in the same directory or in installed through pip (see pip list).
See this for detailed instructions on how to import local files
Note: I am just a beginner and doing this by myself, so if you can reply with basic descriptions, that could help more.
This is the code I wrote
from matplotlib import pyplot as plt
plt.plot([2, 1], [8, 2], 'ro')
However, I get this error. I had a code using same way to import and it used to work just fine. Now that code is not working either.
C:\Users\Tuna\PycharmProjects\start\venv\Scripts\python.exe C:/Users/Tuna/PycharmProjects/start/matplotlib.py
Traceback (most recent call last):
File "C:\Users\Tuna\PycharmProjects\start\matplotlib.py", line 1, in <module>
from matplotlib import pyplot as plt
File "C:\Users\Tuna\PycharmProjects\start\matplotlib.py", line 1, in <module>
from matplotlib import pyplot as plt
ImportError: cannot import name 'pyplot' from partially initialized module 'matplotlib' (most likely due to a circular import) (C:\Users\Tuna\PycharmProjects\start\matplotlib.py)
Process finished with exit code 1
To fix, you just need to rename your file to something that isn't matplotlib.py. Python thinks you are trying to import your own file matplotlib.py to use rather than the actual module and hence why you are getting a circular reference.
This should work fine if you have matplotlib installed, if not pycharm should prompt you to install it which should be the easiest way for you to use it in your project.
Hello l tried to run my python code and the errors is:
Traceback (most recent call last):
File "/home/anelmad/Desktop/simulation/Theano-Tutorials-master/3_net.py", line 5, in <module>
from foxhound.utils.vis import grayscale_grid_vis, unit_scale
ImportError: No module named vis**
knowing that l have correctly installed foxhound.
import theano
from theano import tensor as T
import numpy as np
from load import mnist
from foxhound.utils.vis import grayscale_grid_vis, unit_scale
from scipy.misc import imsave
is Foxhound a scikit? if yes, it doe's not contains utils module. You can clone it on github https://github.com/IndicoDataSolutions/Foxhound
I have met with the same problem. from foxhound vis import grayscale_grid_vis is enough. And I just comment out the other part. And the program works well. It seems that the module is not used.
Here is an issue some of you might have already encountered : I just installed matplotlib using :
pip install matplotlib
on my OS X El Capitan Version 10.11.1. It seems to me that the installation went well, and the packages are properly located in /usr/local/lib/python2.7/site-packages
I get no problem when I try to import matplotlib using :
import matplotlib
Now, when I try to import matplotlib.pyplot in a python script, using :
import matplotlib.pyplot as plt
the program starts hanging, and I have to interrupt it using Keyboard Ctrl + C.
Besides, when I only import matplotlib and try to run this piece of code :
import matplotlib
matplotlib.pyplot
I get this message in the terminal Session :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'pyplot'
Does anyone have a solution to fix this problem ?
I was working with python and matplotlib but my script crashed so I had to turn off the terminal (Ubuntu 12.04, matplotib-1.1.0, python2.7).
Now if I try to run any script it crashes on the line
import matplotlib.pyplot as plt
with the following error
Traceback (most recent call last):
File "new.py", line 4, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-i686.egg/matplotlib/__init__.py", line 151, in <module>
from matplotlib.rcsetup import (defaultParams,
File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-i686.egg/matplotlib/rcsetup.py", line 20, in <module>
from matplotlib.colors import is_color_like
File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-i686.egg/matplotlib/colors.py", line 54, in <module>
import matplotlib.cbook as cbook
File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-i686.egg/matplotlib/cbook.py", line 32, in <module>
import new
File "/home/federico/Documents/doc_uni/idraulica_ambientale/relazione/scripts/variabili/new.py", line 4, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-i686.egg/matplotlib/pyplot.py", line 23, in <module>
from matplotlib import _pylab_helpers, interactive
ImportError: cannot import name interactive
Notice the last line.
I tried removing and reinstalling matplotlib both from source and from pip and easy_install but I can't get away with it. Same error happens if I try to import from within the python interpreter.
I also installed version 1.2.0 to see if that work but it does not.
If you read through files in the stack trace,
new.py-> /matplotlib/__init__.py -> matplotlib/rcsetup.py, /matplotlib/colors.py -> /matplotlib/cbook.py --> /home/federico/Documents/../new.py -> matplotlib/pyplot.py
You have named your module new which is shadowing with an import in matplolib.cbook, which is causing you to try to imort pyplot while you are importing pyplot which aparently blows up (exactly why is above my paygrade). You just need to re-name your module to something other than new.py (and remember to remove the new.pyc file that got created).
As a test run import matplotlib.pyplot as plt in an interactive shell.
FYI this is what you are shadowing.
This import will be removed in mpl 1.3