from numpy import *

NMRTS = ([ 3.55808577,  3.59223114,  3.56645012,  3.5422324 ,  3.52884115,
        3.52708728,  3.53679302,  3.55669148,  3.57647334,  3.52865801,
        3.90752968,  3.8829924 ,  3.82667793,  3.79298524,  3.77681104,
        3.77461005,  3.78609887,  3.81409671,  3.86218649,  3.87058809,
        4.02073245,  4.01258218,  3.93576817,  3.889457  ,  3.86783788,
        3.86534531,  3.88165011,  3.92150751,  3.98926609,  3.98211295,
        4.07508026,  4.08883404,  4.00534248,  3.95224247,  3.92719733,
        3.9245294 ,  3.94389187,  3.99013696,  4.06427717,  4.03603072,
        4.10901763,  4.13741479,  4.05410276,  3.99929676,  3.97321065,
        3.9704604 ,  3.99069376,  4.03847149,  4.11234165,  4.06986755,
        4.13397129,  4.16872991,  4.08956633,  4.03725534,  4.01234035,
        4.00959011,  4.02865234,  4.07393507,  4.14365677,  4.09482121,
        4.1524703 ,  4.18681143,  4.11641677,  4.07105251,  4.04959851,
        4.04693058,  4.06270191,  4.10121125,  4.16225456,  4.11342076,
        4.15957563,  4.19158426,  4.13866489,  4.1057969 ,  4.09023523,
        4.08774266,  4.09799001,  4.12440423,  4.16826818,  4.12095612,
        4.13172724,  4.17901306,  4.15841275,  4.14237356,  4.13354462,
        4.13134362,  4.13548719,  4.14583153,  4.15820716,  4.09478565,
        3.97677578,  4.11782577,  4.11591768,  4.09781841,  4.08585757,
        4.0841037 ,  4.09237903,  4.10615904,  4.10206797,  3.94734802,
        3.41259559,  3.43237731,  3.45341689,  3.45550497,  3.45290656,
        3.45073701,  3.44875668,  3.44124979,  3.41268323,  3.37699035,
        3.78491691,  3.75696226,  3.7503693 ,  3.74437307,  3.7395065 ,
        3.73679322,  3.73585894,  3.73473814,  3.73106315,  3.74035783,
        3.91865412,  3.91603101,  3.8878297 ,  3.86771438,  3.85666368,
        3.85359506,  3.85807433,  3.87013173,  3.88702921,  3.87195973,
        3.98508818,  4.01011741,  3.9749422 ,  3.94689144,  3.93176217,
        3.92847946,  3.93658511,  3.95607861,  3.9795735 ,  3.93777332,
        4.02702716,  4.06993602,  4.03536747,  4.005318  ,  3.98893149,
        3.98554817,  3.99470198,  4.01597777,  4.03874778,  3.97953649,
        4.0578949 ,  4.10853978,  4.07902695,  4.05202348,  4.03706837,
        4.03368505,  4.04140746,  4.05963725,  4.07735154,  4.01040423,
        4.08110104,  4.13125413,  4.11209807,  4.09352698,  4.08280395,
        4.07952125,  4.08322065,  4.09323448,  4.10071022,  4.03378617,
        4.09176434,  4.13842682,  4.13963152,  4.1361003 ,  4.13253497,
        4.12946635,  4.12646026,  4.12193355,  4.10942503,  4.04506995,
        4.06511887,  4.1254477 ,  4.16299874,  4.17894332,  4.18324407,
        4.18053079,  4.17042918,  4.14736758,  4.09954858,  4.02055979,
        3.91917703,  4.0663515 ,  4.11777165,  4.12868771,  4.12859062,
        4.12642107,  4.12193942,  4.10560454,  4.04665742,  3.88357179,
        3.37967392,  3.34036115,  3.35450573,  3.36076865,  3.36166991,
        3.3592694 ,  3.35331178,  3.34111237,  3.3188995 ,  3.34199815,
        3.74730819,  3.65801973,  3.6446395 ,  3.64399597,  3.6434369 ,
        3.64043936,  3.63460303,  3.6274651 ,  3.62986479,  3.70026244,
        3.88861327,  3.82792985,  3.79395289,  3.77966433,  3.77316104,
        3.76977306,  3.76903604,  3.77452019,  3.79642021,  3.83929716,
        3.96100487,  3.93041887,  3.89030825,  3.86825586,  3.85770462,
        3.8540813 ,  3.85689609,  3.86960078,  3.89723817,  3.91101085,
        4.00730123,  3.99608598,  3.95725533,  3.93340501,  3.92165283,
        3.91791887,  3.9217051 ,  3.93597213,  3.96220594,  3.95710835,
        4.04145503,  4.03873419,  4.00545849,  3.9849567 ,  3.97477863,
        3.97104467,  3.97325679,  3.98417529,  4.00485415,  3.99126215,
        4.06709915,  4.0640589 ,  4.04152451,  4.02987952,  4.02416769,
        4.02054436,  4.01851975,  4.02081704,  4.0308782 ,  4.01710514,
        4.0791704 ,  4.07228234,  4.07043596,  4.07428441,  4.07597244,
        4.07258446,  4.06365613,  4.05100326,  4.0407727 ,  4.02985428,
        4.0526587 ,  4.05860049,  4.09294989,  4.11608174,  4.12547269,
        4.12247515,  4.10668881,  4.0757755 ,  4.03044554,  4.00561295,
        3.91571432,  4.00971497,  4.05616171,  4.07206956,  4.07580022,
        4.07339971,  4.06461269,  4.04276834,  3.98825331,  3.87803855,
        3.36203001,  3.28855464,  3.29010458,  3.29264722,  3.29274671,
        3.29022123,  3.28481293,  3.276081  ,  3.26624453,  3.32348716,
        3.72224153,  3.59491395,  3.56676307,  3.56170447,  3.5602066 ,
        3.55705522,  3.55184365,  3.54879702,  3.56568106,  3.67416505,
        3.86619421,  3.76817883,  3.71957888,  3.70097426,  3.69361277,
        3.69005201,  3.68982007,  3.69925722,  3.73547329,  3.81579777,
        3.94152555,  3.87449729,  3.82015436,  3.79390618,  3.78254023,
        3.77873265,  3.78198601,  3.79850261,  3.84006062,  3.89043161,
        3.99016142,  3.94315034,  3.89044699,  3.86254023,  3.85002471,
        3.8461011 ,  3.85026384,  3.8681944 ,  3.90798879,  3.93886113,
        4.0260932 ,  3.98798725,  3.94110849,  3.91671331,  3.90584871,
        3.9019251 ,  3.90443692,  3.9188559 ,  3.9528257 ,  3.97479291,
        4.0529897 ,  4.01479432,  3.97885303,  3.963503  ,  3.95720527,
        3.95339769,  3.95158283,  3.95720128,  3.98035765,  4.00189576,
        4.06571783,  4.0237948 ,  4.0087097 ,  4.0090293 ,  4.01021641,
        4.00665565,  3.99787511,  3.98838804,  3.99108926,  4.01532139,
        4.03966358,  4.01083137,  4.03208838,  4.05165986,  4.06047533,
        4.05732395,  4.04179904,  4.01412233,  3.98159848,  3.9915871 ,
        3.91040697,  3.97257347,  4.00713112,  4.01959764,  4.02263302,
        4.02010754,  4.01176335,  3.99310754,  3.95026336,  3.87186412,
        3.34839912,  3.25816019,  3.25157604,  3.25058022,  3.24938629,
        3.24680558,  3.24258055,  3.23728154,  3.23549809,  3.30952058,
        3.70278901,  3.55610954,  3.51809415,  3.508667  ,  3.50556195,
        3.50234255,  3.4986011 ,  3.49978784,  3.5264299 ,  3.65431496,
        3.84702193,  3.72954428,  3.67089153,  3.64781252,  3.63881103,
        3.63517386,  3.63642784,  3.65018793,  3.69634354,  3.7962103 ,
        3.92337816,  3.83709467,  3.77278164,  3.74206791,  3.7290626 ,
        3.72517356,  3.72990216,  3.75072429,  3.80213824,  3.87186258,
        3.97297449,  3.9069221 ,  3.84437697,  3.81205375,  3.79791696,
        3.79390951,  3.79952475,  3.82170806,  3.8712304 ,  3.92125024,
        4.00969199,  3.95272678,  3.89612552,  3.86738591,  3.85493394,
        3.85092648,  3.85485691,  3.87345661,  3.91703508,  3.95796774,
        4.03719526,  3.9803096 ,  3.93475978,  3.91515882,  3.9073217 ,
        3.90343266,  3.90299307,  3.91270243,  3.94535317,  3.98567968,
        4.0504    ,  3.99000127,  3.96545652,  3.96163834,  3.961338  ,
        3.95770083,  3.95025365,  3.94475292,  3.95680052,  3.99958838,
        4.02521915,  3.97838318,  3.99046511,  4.00601737,  4.01337357,
        4.01015417,  3.99595146,  3.97215881,  3.94870354,  3.9767451 ,
        3.90155218,  3.94783556,  3.97450974,  3.98352963,  3.98530455,
        3.98272385,  3.97552996,  3.96021525,  3.92517345,  3.86267364,
        3.33674114,  3.24242812,  3.23353153,  3.23129487,  3.22956135,
        3.22698065,  3.2232952 ,  3.21923703,  3.21976601,  3.2978626 ,
        3.68802039,  3.536307  ,  3.49542382,  3.48445235,  3.48067394,
        3.47745454,  3.47438644,  3.47711752,  3.50662736,  3.63954634,
        3.83120593,  3.70833082,  3.64660803,  3.62187826,  3.61215782,
        3.60852065,  3.61049358,  3.62590443,  3.67513007,  3.78039431,
        3.90717065,  3.81533217,  3.74786456,  3.7154572 ,  3.70171512,
        3.69782609,  3.70329145,  3.72580721,  3.78037575,  3.85565507,
        3.95663121,  3.88496191,  3.81922978,  3.78519694,  3.77031689,
        3.76630944,  3.77266795,  3.79656086,  3.84927021,  3.90490695,
        3.99334871,  3.93076659,  3.87097833,  3.8405291 ,  3.82733387,
        3.82332641,  3.82800011,  3.84830942,  3.89507489,  3.94162446,
        4.02098775,  3.9585471 ,  3.9098427 ,  3.88854812,  3.87997422,
        3.87608518,  3.87638237,  3.88778535,  3.92359067,  3.96947216,
        4.03458401,  3.9687878 ,  3.94117302,  3.93570408,  3.93468479,
        3.93104762,  3.92431939,  3.92046942,  3.93558706,  3.98377238,
        4.01045053,  3.95858064,  3.96779479,  3.98180271,  3.98848556,
        3.98526616,  3.9717368 ,  3.94948848,  3.92890101,  3.96197648,
        3.8898942 ,  3.93210348,  3.95646523,  3.96424428,  3.96547961,
        3.96289891,  3.95624461,  3.94217074,  3.90944137,  3.85101566,
        3.32599736,  3.23967556,  3.23423818,  3.23315656,  3.23171537,
        3.2291899 ,  3.22532227,  3.2202146 ,  3.21736545,  3.28745451,
        3.67678757,  3.53364362,  3.49685639,  3.48730062,  3.48388517,
        3.48073379,  3.47743979,  3.47889034,  3.50441073,  3.62871109,
        3.81770218,  3.70279278,  3.64498454,  3.62159351,  3.61219397,
        3.60863321,  3.61043933,  3.62466289,  3.67008724,  3.76730574,
        3.89193063,  3.80755062,  3.74376669,  3.7126199 ,  3.699171  ,
        3.69536342,  3.70069973,  3.72211495,  3.77311395,  3.84083669,
        3.94019205,  3.875651  ,  3.81341878,  3.78057255,  3.76595827,
        3.76203466,  3.76829616,  3.79116619,  3.84048946,  3.88889176,
        3.97612383,  3.92048792,  3.86408027,  3.83474563,  3.82178227,
        3.81785866,  3.82246924,  3.84182769,  3.88532637,  3.92482354,
        4.00339478,  3.94784765,  3.90246537,  3.88221672,  3.87383604,
        3.87002846,  3.87029656,  3.88081362,  3.91341098,  3.95230084,
        4.01722581,  3.95840875,  3.93411536,  3.92964855,  3.92879761,
        3.92523685,  3.91849437,  3.91379371,  3.92570321,  3.96682937,
        3.99420961,  3.94956105,  3.9621817 ,  3.97725601,  3.9841539 ,
        3.98100253,  3.96739518,  3.94421565,  3.92032816,  3.94613313,
        3.87437432,  3.92369439,  3.95126472,  3.96010698,  3.96160168,
        3.9590762 ,  3.95227269,  3.93724114,  3.90138428,  3.83583147,
        3.31524312,  3.25232165,  3.25499311,  3.2558237 ,  3.25455623,
        3.25215572,  3.24836683,  3.24159974,  3.23086   ,  3.27756735,
        3.66695173,  3.54889331,  3.52146698,  3.51413891,  3.51089968,
        3.50790214,  3.50474598,  3.50429259,  3.52073836,  3.61990599,
        3.8036057 ,  3.71245389,  3.66363749,  3.64230628,  3.63298591,
        3.62959793,  3.63167799,  3.64420479,  3.68094425,  3.75428959,
        3.87442245,  3.81267838,  3.75742734,  3.72820827,  3.71479678,
        3.71117345,  3.7168485 ,  3.73671987,  3.77949768,  3.82442843,
        3.92021245,  3.87757645,  3.82349646,  3.79243795,  3.77781242,
        3.77407845,  3.78073804,  3.80221326,  3.84369642,  3.87001957,
        3.95436625,  3.92022467,  3.87169962,  3.84398964,  3.83093822,
        3.82720426,  3.83228973,  3.85041642,  3.88634463,  3.90417337,
        3.98051673,  3.9463184 ,  3.9086436 ,  3.88983193,  3.88125984,
        3.87763652,  3.87847216,  3.88793613,  3.9131377 ,  3.93052272,
        3.99416283,  3.95680638,  3.94012056,  3.93692637,  3.93579731,
        3.93240933,  3.92629808,  3.92068786,  3.92529674,  3.94484672,
        3.97230224,  3.94947407,  3.96977738,  3.98622469,  3.99293546,
        3.98993792,  3.97683175,  3.95260299,  3.92131912,  3.9252565 ,
        3.85128351,  3.92167547,  3.95664909,  3.96712461,  3.96868654,
        3.96628603,  3.95966774,  3.94325572,  3.90021381,  3.81360774,
        3.3079868 ,  3.29052864,  3.29807536,  3.29521031,  3.29099403,
        3.28882448,  3.28846202,  3.28590826,  3.27083456,  3.27238156,
        3.65800239,  3.5858514 ,  3.5631239 ,  3.5511408 ,  3.54429493,
        3.54158166,  3.54262667,  3.54749274,  3.55995228,  3.61344331,
        3.78637949,  3.73767481,  3.69273051,  3.66644937,  3.65337812,
        3.6503095 ,  3.65680933,  3.67503253,  3.70867301,  3.7396851 ,
        3.85126004,  3.82951062,  3.77741118,  3.74316946,  3.7260273 ,
        3.72274459,  3.73286313,  3.75854759,  3.79896671,  3.80394517,
        3.89276923,  3.88864711,  3.83710075,  3.80086247,  3.78247213,
        3.77908882,  3.79024645,  3.81771105,  3.85745888,  3.84527856,
        3.92363698,  3.92725088,  3.88076023,  3.84756795,  3.83060901,
        3.8272257 ,  3.83695193,  3.86137053,  3.89606264,  3.87614631,
        3.94727289,  3.95064734,  3.91456705,  3.889805  ,  3.87706909,
        3.87378638,  3.87949867,  3.89570346,  3.92010343,  3.89995803,
        3.95948971,  3.96007062,  3.94453232,  3.9348353 ,  3.92924941,
        3.92618079,  3.92519525,  3.92683435,  3.93106883,  3.91279532,
        3.93820434,  3.95433683,  3.97575335,  3.98571105,  3.98803251,
        3.98531923,  3.97719692,  3.96012219,  3.92843772,  3.89364526,
        3.81456824,  3.92450284,  3.96243012,  3.96839306,  3.96667809,
        3.96450854,  3.96164476,  3.95026301,  3.90480875,  3.778963  ,
        3.36286413,  3.36139463,  3.33327784,  3.31035057,  3.29798322,
        3.29622934,  3.30491118,  3.3235192 ,  3.34563683,  3.33343637,
        3.6875513 ,  3.62354457,  3.56433333,  3.53184155,  3.5166853 ,
        3.51448431,  3.52495518,  3.55175211,  3.60273866,  3.65060971,
        3.79710431,  3.74901526,  3.66949387,  3.62457201,  3.60407256,
        3.60157999,  3.61676512,  3.65523321,  3.72569917,  3.75848481,
        3.85098211,  3.82474839,  3.73872258,  3.68715016,  3.66329633,
        3.6606284 ,  3.67879956,  3.72351706,  3.80019152,  3.81193257,
        3.88498221,  3.87340419,  3.78764734,  3.73443703,  3.70957711,
        3.70682687,  3.72583402,  3.77201607,  3.84833105,  3.84583213,
        3.90993587,  3.9047193 ,  3.82311091,  3.77239561,  3.74870682,
        3.74595658,  3.7637926 ,  3.80747964,  3.87964617,  3.87078579,
        3.92837216,  3.92272578,  3.84979687,  3.80596021,  3.78569751,
        3.78302957,  3.79760961,  3.83459135,  3.89816891,  3.88932262,
        3.93594748,  3.92801734,  3.87239059,  3.84091191,  3.82646991,
        3.82397734,  3.83310502,  3.85812993,  3.90470125,  3.89732798,
        3.91174886,  3.91956523,  3.89606814,  3.88122987,  3.87341888,
        3.87121789,  3.8743435 ,  3.88348692,  3.89875932,  3.87480727,
        3.78155414,  3.88698926,  3.8827454 ,  3.86593658,  3.85499964,
        3.85324576,  3.8604972 ,  3.87298676,  3.87123146,  3.75212638])

from itertools import izip
import scipy as sp
import matplotlib._cntr as cntr
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D


def contour3D(x, y, z, v, levels):
    if len(levels) > 25:
        print 'Too many levels specified, should be no more than 6.'
        return

    # clist is the apparently impossible to find default clist for mpl
    clist = ['b','g','r','c','m','y','k','b','g','r','c','m','y','k','b','g','r','c','m','y','k']
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')

    for lev,color in izip(levels, clist):
        #print lev,color
        # do xy planes
        for k in xrange(0,x.shape[2]):
            c = cntr.Cntr(x[:,:,k], y[:,:,k], v[:,:,k]).trace(lev)
            print c
            #print range(0, len(c)/2)
            for m in xrange(0, len(c)/2):
                ax.plot(c[m][:,0], c[m][:,1], z[0,0,k] * sp.ones_like(c[m][:,0]), color)

        # do xz planes
#         for k in xrange(0, x.shape[1]):
#             c = cntr.Cntr(x[:,k,:], z[:,k,:], v[:,k,:]).trace(lev)
#             for m in xrange(0, len(c)/2):
#                 ax.plot(c[m][:,0], y[0,k,0] * sp.ones_like(c[m][:,0]), c[m][:,1], color)

        # do yz planes
#        for k in xrange(0, x.shape[0]):
#            c = cntr.Cntr(y[k,:,:], z[k,:,:], v[k,:,:]).trace(lev)
#            for m in xrange(0, len(c)/2):
#                ax.plot(x[k,0,0] * sp.ones_like(c[m][:,0]), c[m][:,0], c[m][:,1], color)

    ax.set_xlabel('X Label')
    ax.set_xlim(0,5)
    ax.set_ylabel('Y Label')
    ax.set_ylim(0,5)
    ax.set_zlabel('Z Label')
    ax.set_zlim(0,2.5)

    plt.show()

if __name__ == "__main__":

    x,y,z = sp.mgrid[0.25:5.0:0.5, 0.25:5.0:0.5, 0.125:2.5:0.25]
    v = sp.reshape(NMRTS,shape(x))

    contour3D(x, y, z, v, sp.r_[3:4:10j])

