• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

plplot.py

Go to the documentation of this file.
00001 # Copyright 2002 Gary Bishop and Alan W. Irwin
00002 # Copyright 2008 Andrew Ross
00003 # This file is part of PLplot.
00004 
00005 # PLplot is free software; you can redistribute it and/or modify
00006 # it under the terms of the GNU Library General Public License as published by
00007 # the Free Software Foundation; version 2 of the License.
00008 
00009 # PLplot is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 # GNU Library General Public License for more details.
00013 
00014 # You should have received a copy of the GNU Library General Public License
00015 # along with the file PLplot; if not, write to the Free Software
00016 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00017 
00018 # Wrap raw python interface to C API, plplotc, with this user-friendly version
00019 # which implements some useful variations of the argument lists.
00020 
00021 from plplotc import *
00022 import types
00023 import numpy
00024 
00025 # Redefine plcont to have the user-friendly interface
00026 # Allowable syntaxes:
00027 
00028 # plcont( z, [kx, lx, ky, ly], clev, [pltr, [pltr_data] or [xg, yg, [wrap]]])
00029 # N.B. Brackets represent options here and not python lists!
00030 
00031 # All unbracketed arguments within brackets must all be present or all be
00032 # missing.  Furthermore, z must be a 2D array, kx, lx, ky, ly must all be
00033 # integers, clev must be a 1D array, pltr can be a function reference or
00034 # string, pltr_data is an optional arbitrary data object, xg and yg are 
00035 # optional 1D or 2D arrays and wrap (which only works if xg and yg
00036 # are specified) is 0, 1, or 2.
00037 
00038 # If pltr is a string it must be either "pltr0", "pltr1", or "pltr2" to
00039 # refer to those built-in transformation functions.  Alternatively, the
00040 # function names pltr0, pltr1, or pltr2 may be specified to refer to
00041 # the built-in transformation functions or an arbitrary name for a
00042 # user-defined transformation function may be specified.  Such functions
00043 # must have x, y, and optional pltr_data arguments and return arbitrarily
00044 # transformed x' and y' in a tuple.  The built-in pltr's such as pltr1 and
00045 # pltr2 use pltr_data = tuple(xg, yg), and for this oft-used case (and any
00046 # other user-defined pltr which uses a tuple of two arrays for pltr_data),
00047 # we also provide optional xg and yg arguments separately as an alternative
00048 # to the tuple method of providing these data. Note, that pltr_data cannot
00049 # be in the argument list if xg and yg are there, and vice versa. Also note
00050 # that the built-in pltr0 and some user-defined transformation functions
00051 # ignore the auxiliary pltr_data (or the alternative xg and yg) in which
00052 # case neither pltr_data nor xg and yg need to be specified.
00053 
00054 _plcont = plcont
00055 def plcont(z, *args):
00056     z = numpy.asarray(z)
00057     if len(z.shape) != 2:
00058         raise ValueError, "Expected 2D z array"
00059 
00060     if len(args) > 4 and type(args[0]) == types.IntType:
00061         for i in range(1,4):
00062             if type(args[i]) != types.IntType:
00063                 raise ValueError, "Expected 4 ints for kx,lx,ky,ly"
00064 
00065         else:
00066             # these 4 args are the kx, lx, ky, ly ints
00067             ifdefault_range = 0
00068             kx,lx,ky,ly = args[0:4]
00069             args = args[4:]
00070     else:
00071         ifdefault_range = 1
00072 
00073     if len(args) > 0:
00074         clev = numpy.asarray(args[0])
00075         if len(clev.shape) !=1:
00076             raise ValueError, "Expected 1D clev array"
00077         args = args[1:]
00078     else:
00079         raise ValueError, "Missing clev argument"
00080 
00081     if len(args) > 0 and ( \
00082     type(args[0]) == types.StringType or \
00083     type(args[0]) == types.FunctionType or \
00084     type(args[0]) == types.BuiltinFunctionType):
00085         pltr = args[0]
00086         # Handle the string names for the callbacks though specifying the
00087         # built-in function name directly (without the surrounding quotes) 
00088         # or specifying any user-defined transformation function 
00089         # (following above rules) works fine too.
00090         if type(pltr) == types.StringType:
00091             if pltr == "pltr0":
00092                 pltr = pltr0
00093             elif pltr == "pltr1":
00094                 pltr = pltr1
00095             elif pltr == "pltr2":
00096                 pltr = pltr2
00097             else:
00098                 raise ValueError, "pltr string is unrecognized"
00099 
00100         args = args[1:]
00101         # Handle pltr_data or separate xg, yg, [wrap]
00102         if len(args) == 0:
00103             # Default pltr_data
00104             pltr_data = None
00105         elif len(args) == 1:
00106             #Must be pltr_data
00107             pltr_data = args[0]
00108             args = args[1:]
00109         elif len(args) >= 2:
00110             xg = numpy.asarray(args[0])
00111             if len(xg.shape) < 1 or len(xg.shape) > 2:
00112                 raise ValueError, "xg must be 1D or 2D array"
00113             yg = numpy.asarray(args[1])
00114             if len(yg.shape) != len(xg.shape):
00115                 raise ValueError, "yg must have same number of dimensions as xg"
00116             args = args[2:]
00117             # wrap only relevant if xg and yg specified.
00118             if len(args) > 0:
00119              if type(args[0]) == types.IntType:
00120               wrap = args[0]
00121               args = args[1:]
00122               if len(xg.shape) == 2 and len(yg.shape) == 2 and  \
00123               z.shape == xg.shape and z.shape == yg.shape:
00124                 # handle wrap
00125                 if wrap == 1:
00126                     z = numpy.resize(z, (z.shape[0]+1, z.shape[1]))
00127                     xg = numpy.resize(xg, (xg.shape[0]+1, xg.shape[1]))
00128                     yg = numpy.resize(yg, (yg.shape[0]+1, yg.shape[1]))
00129                 elif wrap == 2:
00130                     z = numpy.transpose(numpy.resize( \
00131                     numpy.transpose(z), (z.shape[1]+1, z.shape[0])))
00132                     xg = numpy.transpose(numpy.resize( \
00133                     numpy.transpose(xg), (xg.shape[1]+1, xg.shape[0])))
00134                     yg = numpy.transpose(numpy.resize( \
00135                     numpy.transpose(yg), (yg.shape[1]+1, yg.shape[0])))
00136                 elif wrap != 0:
00137                     raise ValueError, "Invalid wrap specifier, must be 0, 1 or 2."
00138               elif wrap != 0:
00139                   raise ValueError, "Non-zero wrap specified and xg and yg are not 2D arrays"
00140              else:
00141                  raise ValueError, "Specified wrap is not an integer"
00142             pltr_data = (xg, yg)
00143     else:
00144         # default is identity transformation
00145         pltr = pltr0
00146         pltr_data = None
00147     if len(args) > 0:
00148         raise ValueError, "Too many arguments for plcont"
00149     if ifdefault_range:
00150         # Default is to take full range (still using fortran convention
00151         # for indices which is embedded in the PLplot library API)
00152         kx = 1
00153         lx = z.shape[0]
00154         ky = 1
00155         ly = z.shape[1]
00156     _plcont(z, kx, lx, ky, ly, clev, pltr, pltr_data)
00157 plcont.__doc__ = _plcont.__doc__
00158   
00159 # Redefine plvect to have the user-friendly interface
00160 # Allowable syntaxes:
00161 
00162 # plvect( u, v, scaling, [pltr, [pltr_data] or [xg, yg, [wrap]]])
00163 _plvect = plvect
00164 def plvect(u, v, *args):
00165     u = numpy.asarray(u)
00166     v = numpy.asarray(v)
00167 
00168     if len(u.shape) != 2:
00169         raise ValueError, "Expected 2D u array"
00170     if len(v.shape) != 2:
00171         raise ValueError, "Expected 2D v array"
00172     if (u.shape[0] != v.shape[0]) or (u.shape[1] != v.shape[1]) :
00173         raise ValueError, "Expected u and v arrays to be the same dimensions"
00174 
00175     if len(args) > 0 and (type(args[0]) == types.FloatType or type(args[0]) == numpy.float64) :
00176         scaling = args[0]
00177         args = args[1:]
00178     else:
00179         raise ValueError, "Missing scaling argument"
00180 
00181     if len(args) > 0 and ( \
00182     type(args[0]) == types.StringType or \
00183     type(args[0]) == types.FunctionType or \
00184     type(args[0]) == types.BuiltinFunctionType):
00185         pltr = args[0]
00186         # Handle the string names for the callbacks though specifying the
00187         # built-in function name directly (without the surrounding quotes) 
00188         # or specifying any user-defined transformation function 
00189         # (following above rules) works fine too.
00190         if type(pltr) == types.StringType:
00191             if pltr == "pltr0":
00192                 pltr = pltr0
00193             elif pltr == "pltr1":
00194                 pltr = pltr1
00195             elif pltr == "pltr2":
00196                 pltr = pltr2
00197             else:
00198                 raise ValueError, "pltr string is unrecognized"
00199 
00200         args = args[1:]
00201         # Handle pltr_data or separate xg, yg, [wrap]
00202         if len(args) == 0:
00203             # Default pltr_data
00204             pltr_data = None
00205         elif len(args) == 1:
00206             #Must be pltr_data
00207             pltr_data = args[0]
00208             args = args[1:]
00209         elif len(args) >= 2:
00210             xg = numpy.asarray(args[0])
00211             if len(xg.shape) < 1 or len(xg.shape) > 2:
00212                 raise ValueError, "xg must be 1D or 2D array"
00213             yg = numpy.asarray(args[1])
00214             if len(yg.shape) != len(xg.shape):
00215                 raise ValueError, "yg must have same number of dimensions as xg"
00216             args = args[2:]
00217             # wrap only relevant if xg and yg specified.
00218             if len(args) > 0:
00219              if type(args[0]) == types.IntType:
00220               wrap = args[0]
00221               args = args[1:]
00222               if len(xg.shape) == 2 and len(yg.shape) == 2 and  \
00223               u.shape == xg.shape and u.shape == yg.shape:
00224                 # handle wrap
00225                 if wrap == 1:
00226                     u = numpy.resize(u, (u.shape[0]+1, u.shape[1]))
00227                     v = numpy.resize(v, (v.shape[0]+1, v.shape[1]))
00228                     xg = numpy.resize(xg, (xg.shape[0]+1, xg.shape[1]))
00229                     yg = numpy.resize(yg, (yg.shape[0]+1, yg.shape[1]))
00230                 elif wrap == 2:
00231                     u = numpy.transpose(numpy.resize( \
00232                     numpy.transpose(u), (u.shape[1]+1, u.shape[0])))
00233                     v = numpy.transpose(numpy.resize( \
00234                     numpy.transpose(v), (v.shape[1]+1, v.shape[0])))
00235                     xg = numpy.transpose(numpy.resize( \
00236                     numpy.transpose(xg), (xg.shape[1]+1, xg.shape[0])))
00237                     yg = numpy.transpose(numpy.resize( \
00238                     numpy.transpose(yg), (yg.shape[1]+1, yg.shape[0])))
00239                 elif wrap != 0:
00240                     raise ValueError, "Invalid wrap specifier, must be 0, 1 or 2."
00241               elif wrap != 0:
00242                   raise ValueError, "Non-zero wrap specified and xg and yg are not 2D arrays"
00243              else:
00244                  raise ValueError, "Specified wrap is not an integer"
00245             pltr_data = (xg, yg)
00246     else:
00247         # default is identity transformation
00248         pltr = pltr0
00249         pltr_data = None
00250     if len(args) > 0:
00251         raise ValueError, "Too many arguments for plvect"
00252     _plvect(u, v, scaling, pltr, pltr_data)
00253 plvect.__doc__ = _plvect.__doc__
00254 
00255 # Redefine plimagefr to have the user-friendly interface
00256 # Allowable syntaxes:
00257 
00258 # plimagefr( img, xmin, xmax, ymin, ymax, zmin, zmax, valuemin, valuemax, [pltr, [pltr_data] or [xg, yg, [wrap]]])
00259 _plimagefr = plimagefr
00260 def plimagefr(img, *args):
00261     img = numpy.asarray(img)
00262 
00263     if len(img.shape) != 2:
00264         raise ValueError, "Expected 2D img array"
00265 
00266     if len(args) >= 8 :
00267         for i in range(8) :
00268             if (type(args[i]) != types.FloatType and \
00269                 type(args[i]) != numpy.float64 and \
00270                 type(args[i]) != types.IntType) : 
00271                 raise ValueError, "Expected 8 numbers for xmin, xmax, ymin, ymax, zmin, zmax, valuemin, valuemax"
00272         else:
00273             # These 8 args are xmin, xmax, ymin, ymax, zmin, zmax, valuemin, valuemax
00274             xmin, xmax, ymin, ymax, zmin, zmax, valuemin, valuemax = args[0:8]
00275             args = args[8:]
00276     else:
00277         raise ValueError, "Expected 8 numbers for xmin, xmax, ymin, ymax, zmin, zmax, valuemin, valuemax"
00278 
00279     if len(args) > 0 and ( \
00280     type(args[0]) == types.StringType or \
00281     type(args[0]) == types.FunctionType or \
00282     type(args[0]) == types.BuiltinFunctionType):
00283         pltr = args[0]
00284         # Handle the string names for the callbacks though specifying the
00285         # built-in function name directly (without the surrounding quotes) 
00286         # or specifying any user-defined transformation function 
00287         # (following above rules) works fine too.
00288         if type(pltr) == types.StringType:
00289             if pltr == "pltr0":
00290                 pltr = pltr0
00291             elif pltr == "pltr1":
00292                 pltr = pltr1
00293             elif pltr == "pltr2":
00294                 pltr = pltr2
00295             else:
00296                 raise ValueError, "pltr string is unrecognized"
00297 
00298         args = args[1:]
00299         # Handle pltr_data or separate xg, yg, [wrap]
00300         if len(args) == 0:
00301             # Default pltr_data
00302             pltr_data = None
00303         elif len(args) == 1:
00304             #Must be pltr_data
00305             pltr_data = args[0]
00306             args = args[1:]
00307         elif len(args) >= 2:
00308             xg = numpy.asarray(args[0])
00309             if len(xg.shape) < 1 or len(xg.shape) > 2:
00310                 raise ValueError, "xg must be 1D or 2D array"
00311             yg = numpy.asarray(args[1])
00312             if len(yg.shape) != len(xg.shape):
00313                 raise ValueError, "yg must have same number of dimensions as xg"
00314             args = args[2:]
00315             # wrap only relevant if xg and yg specified.
00316             if len(args) > 0:
00317              if type(args[0]) == types.IntType:
00318               wrap = args[0]
00319               args = args[1:]
00320               if len(xg.shape) == 2 and len(yg.shape) == 2 and  \
00321               img.shape[0] == xg.shape[0]-1 and img.shape[1] == xg.shape[1]-1:
00322                 # handle wrap
00323                 if wrap == 1:
00324                     img = numpy.resize(img, (img.shape[0]+1, u.shape[1]))
00325                     xg = numpy.resize(xg, (xg.shape[0]+1, xg.shape[1]))
00326                     yg = numpy.resize(yg, (yg.shape[0]+1, yg.shape[1]))
00327                 elif wrap == 2:
00328                     img = numpy.transpose(numpy.resize( \
00329                     numpy.transpose(img), (img.shape[1]+1, img.shape[0])))
00330                     xg = numpy.transpose(numpy.resize( \
00331                     numpy.transpose(xg), (xg.shape[1]+1, xg.shape[0])))
00332                     yg = numpy.transpose(numpy.resize( \
00333                     numpy.transpose(yg), (yg.shape[1]+1, yg.shape[0])))
00334                 elif wrap != 0:
00335                     raise ValueError, "Invalid wrap specifier, must be 0, 1 or 2."
00336               elif wrap != 0:
00337                   raise ValueError, "Non-zero wrap specified and xg and yg are not 2D arrays"
00338              else:
00339                  raise ValueError, "Specified wrap is not an integer"
00340             pltr_data = (xg, yg)
00341     else:
00342         # default is identity transformation
00343         pltr = pltr0
00344         pltr_data = None
00345     if len(args) > 0:
00346         raise ValueError, "Too many arguments for plimagefr"
00347     _plimagefr(img, xmin, xmax, ymin, ymax, zmin, zmax, valuemin, valuemax, pltr, pltr_data)
00348 plimagefr.__doc__ = _plimagefr.__doc__
00349 
00350 # Redefine plshades to have the user-friendly interface
00351 # Allowable syntaxes:
00352 
00353 # plshades(z,  [xmin, xmax, ymin, ymax,] clev, \
00354 # fill_width, [cont_color, cont_width,], rect, \
00355 # [pltr, [pltr_data] or [xg, yg, [wrap]]])
00356  
00357 _plshades = plshades
00358 def plshades(z, *args):
00359     z = numpy.asarray(z)
00360     if len(z.shape) != 2:
00361         raise ValueError, "Expected 2D z array"
00362 
00363     if len(args) > 4 and \
00364     (type(args[0]) == types.FloatType or type(args[0]) == numpy.float64 or type(args[0]) == types.IntType) and \
00365     (type(args[1]) == types.FloatType or type(args[1]) == numpy.float64 or type(args[1]) == types.IntType) and \
00366     (type(args[2]) == types.FloatType or type(args[2]) == numpy.float64 or type(args[2]) == types.IntType) and \
00367     (type(args[3]) == types.FloatType or type(args[3]) == numpy.float64 or type(args[3]) == types.IntType):
00368         # These 4 args are xmin, xmax, ymin, ymax
00369         xmin, xmax, ymin, ymax = args[0:4]
00370         args = args[4:]
00371     else:
00372         # These values are ignored if pltr and pltr_data are defined in any case.
00373         # So pick some convenient defaults that work for the pltr0, None case
00374         xmin = -1.
00375         xmax = 1.
00376         ymin = -1.
00377         ymax = 1.
00378 
00379     # clev must be present.
00380     if len(args) > 0:
00381         clev = numpy.asarray(args[0])
00382         if len(clev.shape) !=1:
00383             raise ValueError, "Expected 1D clev array"
00384         args = args[1:]
00385     else:
00386         raise ValueError, "Missing clev argument"
00387 
00388     # fill_width must be present
00389     if len(args) > 0 and type(args[0]) == types.IntType:
00390         fill_width = args[0]
00391         args = args[1:]
00392     else:
00393         raise ValueError, "Missing fill_width argument"
00394 
00395     # cont_color and cont_width are optional.
00396     if len(args) > 2 and \
00397     type(args[0]) == types.IntType and \
00398     type(args[1]) == types.IntType:
00399         # These 2 args are 
00400         cont_color, cont_width = args[0:2]
00401         args = args[2:]
00402     else:
00403         # Turn off contouring.
00404         cont_color, cont_width = (0,0)
00405 
00406     # rect must be present.
00407     if len(args) > 0 and type(args[0]) == types.IntType:
00408         rect = args[0]
00409         args = args[1:]
00410     else:
00411         raise ValueError, "Missing rect argument"
00412 
00413     if len(args) > 0 and ( \
00414     type(args[0]) == types.NoneType or \
00415     type(args[0]) == types.StringType or \
00416     type(args[0]) == types.FunctionType or \
00417     type(args[0]) == types.BuiltinFunctionType):
00418         pltr = args[0]
00419         # Handle the string names for the callbacks though specifying the
00420         # built-in function name directly (without the surrounding quotes) 
00421         # or specifying any user-defined transformation function 
00422         # (following above rules) works fine too.
00423         if type(pltr) == types.StringType:
00424             if pltr == "pltr0":
00425                 pltr = pltr0
00426             elif pltr == "pltr1":
00427                 pltr = pltr1
00428             elif pltr == "pltr2":
00429                 pltr = pltr2
00430             else:
00431                 raise ValueError, "pltr string is unrecognized"
00432 
00433         args = args[1:]
00434         # Handle pltr_data or separate xg, yg, [wrap]
00435         if len(args) == 0:
00436             # Default pltr_data
00437             pltr_data = None
00438         elif len(args) == 1:
00439             #Must be pltr_data
00440             pltr_data = args[0]
00441             args = args[1:]
00442         elif len(args) >= 2:
00443             xg = numpy.asarray(args[0])
00444             if len(xg.shape) < 1 or len(xg.shape) > 2:
00445                 raise ValueError, "xg must be 1D or 2D array"
00446             yg = numpy.asarray(args[1])
00447             if len(yg.shape) != len(xg.shape):
00448                 raise ValueError, "yg must have same number of dimensions as xg"
00449             args = args[2:]
00450             # wrap only relevant if xg and yg specified.
00451             if len(args) > 0:
00452              if type(args[0]) == types.IntType:
00453               wrap = args[0]
00454               args = args[1:]
00455               if len(xg.shape) == 2 and len(yg.shape) == 2 and  \
00456               z.shape == xg.shape and z.shape == yg.shape:
00457                 # handle wrap
00458                 if wrap == 1:
00459                     z = numpy.resize(z, (z.shape[0]+1, z.shape[1]))
00460                     xg = numpy.resize(xg, (xg.shape[0]+1, xg.shape[1]))
00461                     yg = numpy.resize(yg, (yg.shape[0]+1, yg.shape[1]))
00462                 elif wrap == 2:
00463                     z = numpy.transpose(numpy.resize( \
00464                     numpy.transpose(z), (z.shape[1]+1, z.shape[0])))
00465                     xg = numpy.transpose(numpy.resize( \
00466                     numpy.transpose(xg), (xg.shape[1]+1, xg.shape[0])))
00467                     yg = numpy.transpose(numpy.resize( \
00468                     numpy.transpose(yg), (yg.shape[1]+1, yg.shape[0])))
00469                 elif wrap != 0:
00470                     raise ValueError, "Invalid wrap specifier, must be 0, 1 or 2."
00471               elif wrap != 0:
00472                   raise ValueError, "Non-zero wrap specified and xg and yg are not 2D arrays"
00473              else:
00474                  raise ValueError, "Specified wrap is not an integer"
00475             pltr_data = (xg, yg)
00476     else:
00477         # default is identity transformation
00478         pltr = pltr0
00479         pltr_data = None
00480     if len(args) > 0:
00481         raise ValueError, "Too many arguments for plshades"
00482 
00483     _plshades(z, xmin, xmax, ymin, ymax, clev, \
00484     fill_width, cont_color, cont_width, rect, pltr, pltr_data)
00485 plshades.__doc__ = _plshades.__doc__
00486   
00487 # Redefine plshade to have the user-friendly interface
00488 # Allowable syntaxes:
00489 
00490 # _plshade(z, [xmin, xmax, ymin, ymax,] \
00491 # shade_min, shade_max, sh_cmap, sh_color, sh_width, \
00492 # [min_color, min_width, max_color, max_width,] rect, \
00493 # [pltr, [pltr_data] or [xg, yg, [wrap]]])
00494 
00495 # plshade(z,  [xmin, xmax, ymin, ymax,] clev, \
00496 # fill_width, [cont_color, cont_width,], rect, \
00497 # [pltr, [pltr_data] or [xg, yg, [wrap]]])
00498  
00499 _plshade = plshade
00500 def plshade(z, *args):
00501     z = numpy.asarray(z)
00502     if len(z.shape) != 2:
00503         raise ValueError, "Expected 2D z array"
00504 
00505     # Extra check on shade_min = float on end is absolutely necessary
00506     # to unambiguously figure out where we are in the argument list.
00507     if len(args) > 9 and \
00508     (type(args[0]) == types.FloatType or type(args[0]) == numpy.float64 or type(args[0]) == types.IntType) and \
00509     (type(args[1]) == types.FloatType or type(args[1]) == numpy.float64 or type(args[1]) == types.IntType) and \
00510     (type(args[2]) == types.FloatType or type(args[2]) == numpy.float64 or type(args[2]) == types.IntType) and \
00511     (type(args[3]) == types.FloatType or type(args[3]) == numpy.float64 or type(args[3]) == types.IntType) and \
00512     (type(args[4]) == types.FloatType or type(args[4]) == numpy.float64) :
00513         # These 4 args are xmin, xmax, ymin, ymax
00514         xmin, xmax, ymin, ymax = args[0:4]
00515         args = args[4:]
00516     else:
00517         # These values are ignored if pltr and pltr_data are defined in any case.
00518         # So pick some convenient defaults that work for the pltr0, None case
00519         xmin = -1.
00520         xmax = 1.
00521         ymin = -1.
00522         ymax = 1.
00523 
00524     # shade_min, shade_max, sh_cmap, sh_color, sh_width, must be present.
00525     # sh_color can be either integer or float.
00526     if len(args) > 5 and \
00527     (type(args[0]) == types.FloatType or type(args[0]) == numpy.float64) and \
00528     (type(args[1]) == types.FloatType or type(args[1]) == numpy.float64) and \
00529     type(args[2]) == types.IntType and \
00530     (type(args[3]) == types.FloatType or type(args[3]) == numpy.float64 or type(args[3]) == types.IntType) and \
00531     type(args[4]) == types.IntType:
00532         shade_min, shade_max, sh_cmap, sh_color, sh_width = args[0:5]
00533         args = args[5:]
00534     else:
00535         raise ValueError, \
00536         "shade_min, shade_max, sh_cmap, sh_color, sh_width, must be present"
00537 
00538     # min_color, min_width, max_color, max_width are optional.
00539     if len(args) > 4 and \
00540     type(args[0]) == types.IntType and \
00541     type(args[1]) == types.IntType and \
00542     type(args[2]) == types.IntType and \
00543     type(args[3]) == types.IntType:
00544         # These 4 args are 
00545         min_color, min_width, max_color, max_width = args[0:4]
00546         args = args[4:]
00547     else:
00548         # Turn off boundary colouring
00549         min_color, min_width, max_color, max_width = (0,0,0,0)
00550 
00551     # rect must be present.
00552     if len(args) > 0 and type(args[0]) == types.IntType:
00553         rect = args[0]
00554         args = args[1:]
00555     else:
00556         raise ValueError, "Missing rect argument"
00557 
00558     if len(args) > 0 and ( \
00559     type(args[0]) == types.NoneType or \
00560     type(args[0]) == types.StringType or \
00561     type(args[0]) == types.FunctionType or \
00562     type(args[0]) == types.BuiltinFunctionType):
00563         pltr = args[0]
00564         # Handle the string names for the callbacks though specifying the
00565         # built-in function name directly (without the surrounding quotes) 
00566         # or specifying any user-defined transformation function 
00567         # (following above rules) works fine too.
00568         if type(pltr) == types.StringType:
00569             if pltr == "pltr0":
00570                 pltr = pltr0
00571             elif pltr == "pltr1":
00572                 pltr = pltr1
00573             elif pltr == "pltr2":
00574                 pltr = pltr2
00575             else:
00576                 raise ValueError, "pltr string is unrecognized"
00577 
00578         args = args[1:]
00579         # Handle pltr_data or separate xg, yg, [wrap]
00580         if len(args) == 0:
00581             # Default pltr_data
00582             pltr_data = None
00583         elif len(args) == 1:
00584             #Must be pltr_data
00585             pltr_data = args[0]
00586             args = args[1:]
00587         elif len(args) >= 2:
00588             xg = numpy.asarray(args[0])
00589             if len(xg.shape) < 1 or len(xg.shape) > 2:
00590                 raise ValueError, "xg must be 1D or 2D array"
00591             yg = numpy.asarray(args[1])
00592             if len(yg.shape) != len(xg.shape):
00593                 raise ValueError, "yg must have same number of dimensions as xg"
00594             args = args[2:]
00595             # wrap only relevant if xg and yg specified.
00596             if len(args) > 0:
00597              if type(args[0]) == types.IntType:
00598               wrap = args[0]
00599               args = args[1:]
00600               if len(xg.shape) == 2 and len(yg.shape) == 2 and  \
00601               z.shape == xg.shape and z.shape == yg.shape:
00602                 # handle wrap
00603                 if wrap == 1:
00604                     z = numpy.resize(z, (z.shape[0]+1, z.shape[1]))
00605                     xg = numpy.resize(xg, (xg.shape[0]+1, xg.shape[1]))
00606                     yg = numpy.resize(yg, (yg.shape[0]+1, yg.shape[1]))
00607                 elif wrap == 2:
00608                     z = numpy.transpose(numpy.resize( \
00609                     numpy.transpose(z), (z.shape[1]+1, z.shape[0])))
00610                     xg = numpy.transpose(numpy.resize( \
00611                     numpy.transpose(xg), (xg.shape[1]+1, xg.shape[0])))
00612                     yg = numpy.transpose(numpy.resize( \
00613                     numpy.transpose(yg), (yg.shape[1]+1, yg.shape[0])))
00614                 elif wrap != 0:
00615                     raise ValueError, "Invalid wrap specifier, must be 0, 1 or 2."
00616               elif wrap != 0:
00617                   raise ValueError, "Non-zero wrap specified and xg and yg are not 2D arrays"
00618              else:
00619                  raise ValueError, "Specified wrap is not an integer"
00620             pltr_data = (xg, yg)
00621     else:
00622         # default is identity transformation
00623         pltr = pltr0
00624         pltr_data = None
00625     if len(args) > 0:
00626         raise ValueError, "Too many arguments for plshade"
00627 
00628     _plshade(z,  xmin, xmax, ymin, ymax, \
00629     shade_min, shade_max, sh_cmap, sh_color, sh_width, \
00630     min_color, min_width, max_color, max_width, rect, pltr, pltr_data)
00631 plshade.__doc__ = _plshade.__doc__
00632 
00633 # Redefine plscmap1l to have the user-friendly interface
00634 # Allowable syntaxes:
00635 
00636 # plscmap1l(itype, pos, coord1, coord2, coord3[, rev])
00637  
00638 _plscmap1l = plscmap1l
00639 def plscmap1l(itype, pos, coord1, coord2, coord3, *args):
00640 
00641     pos = numpy.asarray(pos)
00642     if len(pos.shape) != 1:
00643         raise ValueError, "Expected 1D pos array"
00644                 
00645     if len(args) == 0:
00646         # Default rev
00647         rev = numpy.zeros(pos.shape[0]-1,dtype="int")
00648     elif len(args) == 1:
00649         rev = numpy.asarray(args[0])
00650     else:
00651         raise ValueError, "Too many arguments to plscmap1l"
00652     _plscmap1l(itype, pos, coord1, coord2, coord3, rev)
00653 plscmap1l.__doc__ = _plscmap1l.__doc__

Generated on Wed Oct 12 2011 20:42:22 for PLplot by  doxygen 1.7.1