I am trying to define a function using cwt in Python, however, I get the error message
global name 'cwt' is not defined
This is the code that I am using:
import os
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.pyplot import specgram
import librosa
import librosa.display
import numpy as np
from ssqueezepy import cwt
from ssqueezepy.visuals import plot, imshow
from numba import jit
#jit
def scaleogram_convert(data):
Wx, scales = cwt(data, 'morlet')
Wx = abs(Wx) # remove complex component
return Wx
img3 = scaleogram_convert(trimmed)
How can I get this function to work correctly when called?
Any help is greatly appreciated!
Related
i'm having what i think is a gtk error in python while trying to recognize some faces and then apply a gaussian blur, i'm new in python! Here is the error:
*Gtk-WARNING *: 00:11:03.559: Theme parsing error: gtk.css:6321:10: "height" is not a valid property name
i'm currently using Archlinux and python 3+, i checked ~/.config and my Gtk is 2.0, idk if that is the issue and i also don't know how to change it/ update it.
Here is the code i'm triying to compile:
from skimage.filters import gaussian
from skimage import color
from skimage import data
import scipy.misc
import os
import sys
import plots
import matplotlib.pyplot as plt
from PIL import Image
path = "/home/carlos/python/img/jaja.jpeg"
img = plt.imread("/home/carlos/python/img/girl.jpeg")
#plt.show(img)
trained_file = data.lbp_frontal_face_cascade_filename()
detector = Cascade(trained_file)
detected = detector.detect_multi_scale(img=img, scale_factor=1.2, step_ratio=1, min_size=(50,50), max_size=(200,200))
print(detected)
This is my first time asking a question. I am trying to use "pysheds" to analyze some hydrologic DEM files. The developer as some pretty thorough "how to" videos but when I try to load the DEM file in the way that they show I get the following error:
module 'pysheds.grid' has no attribute 'from_raster'
here's my code
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import geopandas as gpd
import pysheds
import pysheds.grid as Grid
import mplleaflet
grid = Grid.from_raster('path.tif', data_name = 'dem')`
I checked the print(dir(Grid)) in the console and didn't see this attribute listed.
Am I missing something?
Thanks!
According to documentation, you should import Grid from pysheds.grid like this:
from pysheds.grid import Grid
grid = Grid.from_raster('n30w100_con', data_name='dem')
grid.read_raster('n30w100_dir', data_name='dir')
grid.view('dem')
instead of
import pysheds.grid as Grid
I am having an issue where I cannot call the 'pyplot' element of 'matplotlib'. From the code below you can see I've had to add a "TkAgg" for the mattplotlib element to work, which is a common issue.
import matplotlib
matplotlib.use("TkAgg")
However, now I cannot add the '.pyplot' to the import. I've tried the following:
import matplotlib.pyplot as plt
plt.use("TkAgg")
But this gives me the error:
AttributeError: module 'matplotlib.pyplot' has no attribute 'use'
How can I get around this as my code requires pyplot to function, but I cannot work out how to import it while still having to use ".use("TkAgg").
I am running Python 3.6.2 and I am using Tkinter to develop my program
Those are two entirely different things. You import matplotlib to be able to set the backend. Then you need to still import pyplot to be able to use it afterwards.
import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
# ... rest of code
If you use the use() function, this must be done before importing matplotlib.pyplot. Calling use() after pyplot has been imported will have no effect.
import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
check with :
matplotlib.get_backend()
I'm trying to make a plot:
from matplotlib import *
import sys
from pylab import *
f = figure ( figsize =(7,7) )
But I get this error when I try to execute it:
File "mratio.py", line 24, in <module>
f = figure( figsize=(7,7) )
TypeError: 'module' object is not callable
I have run a similar script before, and I think I've imported all the relevant modules.
The figure is a module provided by matplotlib.
You can read more about it in the Matplotlib documentation
I think what you want is matplotlib.figure.Figure (the class, rather than the module)
It's documented here
from matplotlib import *
import sys
from pylab import *
f = figure.Figure( figsize =(7,7) )
or
from matplotlib import figure
f = figure.Figure( figsize =(7,7) )
or
from matplotlib.figure import Figure
f = Figure( figsize =(7,7) )
or to get pylab to work without conflicting with matplotlib:
from matplotlib import *
import sys
import pylab as pl
f = pl.figure( figsize =(7,7) )
You need to do:
matplotlib.figure.Figure
Here,
matplotlib.figure is a package (module), and `Figure` is the method
Reference here.
So you would have to call it like this:
f = figure.Figure(figsize=(7,7))
To prevent future errors regarding matplotlib.pyplot, try doing this:
import matplotlib.pyplot as plt
If you use Jupyter notebooks and use: %matplotlib inline, make sure that the "%matplotlib inline FOLLOWS the import matplotlib.pyplot as plt
Karthikr's answer works but might not eliminate errors in other lines of code related to the pyplot module.
Happy coding!!
Instead of
from matplotlib import *
use
import matplotlib.pyplot as plt
For Jupyter notebook I solved this issue by importig matplotlib.pyplot instead.
import matplotlib.pyplot as plt
%matplotlib notebook
Making plots with f = plt.figure() now works.
Wrong Library:
import matplotlib as plt
plt.figure(figsize=(7, 7))
TypeError: 'module' object is not callable
But
Correct Library:
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 7))
Above code worked for me for the same error.
I just finished a horrible install of scipy, numpy, and matplotlib on OSX Lion. For some reason, I can't do a:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3d
Error output is:
Traceback (most recent call last):
File "3dPlot.py", line 2, in <module>
from mpl_toolkits.mplot3d import Axes3d
ImportError: cannot import name Axes3d
but I can do:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
Is there a different between Axes3d and axes3d, or is my file just named with a lowercase 'a' for some reason?
The following two things work for me (watch your capitalization):
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d import axes3d
But I get the same error for what you wrote (with the d in 3d in lower case). Note that the two imports that do work are not equivalent.
from mpl_toolkits.mplot3d import Axes3D
Please use above command to use the 3D image for an object