'module' object has no attribute 'cmap' in cubehelix python - python

I'm trying to use cubehelix in python however I've been getting simple problems which I don't think should be showing up. The code I'm using is the following:
import matplotlib.pyplot as plt
import numpy as np
import cubehelix
cx1 = cubehelix.cmap(reverse=True)
alplot = plt.imshow(rtotal_rotated,vmax=1100,extent[-21,19,23,-17],cmap=cx1)
However the following error comes up when I run the code:
AttributeError: 'module' object has no attribute 'cmap'
I know this can't be right since I'm simply following the code from this tutorial
http://www.ifweassume.com/2014/04/cubehelix-colormap-for-python.html
So I'm not sure why it's breaking.

Very like that the script imports itself, i.e. your script is named cubehelix.py. So, if you have file named cubehelix.py in your current working directory, rename it to my_cubehelix.py and try again.

Related

I cannot import pandas as I keep getting a weird error

when I go to import panda from terminal or VS code studio I get the following error
AttributeError: module 'calendar' has no attribute 'day_abbr'
the only code I've written is:
import pandas as pd
is there a reason for this? how can I prevent this?

Jupyter Import Module AND use function. How can I do that?

I need to import a function classify(par1, par2, par3)
from a module called _Y03_Labeling. Importing does work, but using its functions with more than one extra parameter doesnt work.
Question : How can I import functions with more than one Parameter?
.
What I already tried ( Without Success):
I successfully can run the whole notebook2 from notebook1 with the following code:
import _Y03_Labeling
Labeling =_Y03_Labeling
(Why I know if it is successful? Because its comments are printed out). Whenever I try to run:
X,y = classify(a,b,c)
I get the following error: "TypeError: 'module' object is not callable"
I tried many variations from the import line, including:
import _Y03_Labeling
Labeling =_Y03_Labeling
X,y = Labeling.classify(a,b,c)
# or:
from _Y03_Labeling import classify
# or:
import _Y03_Labeling
X,y = _Y03_Labeling .classify(a,b,c)
Sadly none of them worked for me.
Things i also did so far:
shutting down the _Y03_Labeling notebook before I run the main Notebook
putting the function in the second notebook into a class, importing the class from the notebook and calling the function. (works only if function needs 1 parameter)
also i didnt forgot "self" i the function declaration with the class try.
I am glad, this forum exists and thankful for every possible help.

Inheritance AttributeError: 'module' object has no attribute

I have a pycharm project with two .py files signal.py and moving_average.py.
signal.py looks something like:
class signal_class(object):
long_short = 0
underlying = ""
def abc(self,...):
and moving_average.py looks something like:
import signal
import stock_wrapper
import pandas as pd
import signal
class SMA(signal.signal_class): #Error throws here.
df = None
s_w = None
Which looks correct to me but when I try to run I get the following error:
class SMA(signal.signal_class):
AttributeError: 'module' object has no attribute 'signal_class'
The error is thrown from the line market above.
I thought I followed the tutorial quite closely but I am unsure what is causing this.
Thank you very much for anyone who can help on this.
Python has a builtin package named signal
Python2
Python3
So, when you do import signal that is being imported.
If you want to import your signal_class - either rename signal.py or do
from .signal import signal_class
and inherit SMA from there

skimage ImageCollection and Python3

I am having trouble using the skimage ImageCollection (http://scikit-image.org/docs/dev/api/skimage.io.html#imagecollection) object in Python3. For example, in python 2,7, I was using it as follows:
import skimage.io as io
files = io.ImageCollection('/home/luca/sequence/*.*)
method_do_something(files[0])
This worked fine. When I use it in Python 3.4, the creation of the ImageCollection object works fine and len(files) returns the correct amount of files.
However, when I try the files[0] call, I get the following error:
AttributeError: 'builtin_function_or_method' object has no attribute 'keys'
I was wondering if anyone knows of a workaround that might work on both 2.7 and python 3.x

can import numpy module but cannot use functionalities

i had succesfully installed numpy (numpy-1.6.2-win32-superpack-python2.7.exe). But, whenever i try to call any functions i am getting following the error below. Thanks in advance for help.
import numpy as np
if __name__ == "__main__":
k = np.arange(10)
AttributeError: 'module' object has no attribute 'arange'
Echoing one of the comments above (as I just had this problem, over 4 years later):
You probably named your file numpy.py. When trying to load a module, I believe the path checks the current directory first, and thus it isn't found.
For sanity, to check that it really is this issue, you should run the Python REPL (python) and type:
import numpy as np, followed by dir(np)
And you should see all of the actual functions as output.
This might also happen because you probably named your program file numpy.py (i made the same mistake)
try the following:
for x in dir(np):
print x
this should list all methods etc of your import, that way you can see if arange() is available.
you could also try
from numpy import *
and then just try:
print arange(10)
Can't think of much else. Odd that the import does not produce an error if arange is not there.

Categories

Resources