Error 'Contour' not Defined - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Error 'Contour' not Defined (/thread-36638.html) |
Error 'Contour' not Defined - DaveG - Mar-12-2022 Hi - I'm new to Python and are working with debugging a script that was developed for Python 2.7. This is my error: I just wonder if 'contour' is a module I should have available. These are the modules the script calls for:from scipy import * #from pylab import * from numpy import * import sys from degrees2utm import * from copy import deepcopy from matplotlib.patches import PathPatchHas it something to do with 'matplotlib.patches import PathPatch' because this is the only module I could not find to load? Kind Regards Dave RE: Error 'Contour' not Defined - deanhystad - Mar-12-2022 This is one of the many problems with wildcard imports. You have no idea where to look for contour. But if I had to guess I would say it is in pylab. A quick google search of pylab and contour brings up examples of how to use countour() and even a demo! RE: Error 'Contour' not Defined - DaveG - Mar-12-2022 Hi Deanhystad Oh, because I'm real new to it. Is the problem that my Python 2.7 is not recognizing the contour function. How do I get it to do so" RE: Error 'Contour' not Defined - deanhystad - Mar-13-2022 I think contour is in the pylab module. You are not importing the pylab module. The line that imports the pylab module is commented out. Are you going to be a project? If this is your first foray into Python I don't think you should start with scipy, numpy and matplotlib. Are you converting existing code from Python 2.7 to a new version of Python? This can be a difficult task for a new programmer. Not only do are you learning Python, but you are learning two very different version of Python and having to keep straight which version has which features. And I am leery about learning from this code. The wildcard imports make me think it was not written by a good programmer. This is all bad: from scipy import * #from pylab import * # <- This import is commented out from numpy import * from degrees2utm import *A good python programmer would write this as: import scipy import numpy import pylab import degrees2utmThen when the programmer used the contour pylab contour function it would look like this: cs = pylab.contour(kxx, kyy, -kelevation, [collapse_depth])Now if there is a problem with countour at least you know which module is responsible. And maybe you would look at pyplot and controur and find out why the import is commented out. Then you would see that pyplot is an interface to matplotlib.pyplot, and that pyplot also has a contour. |