这个错误令我感到困惑 . 我正在尝试将curve_fit设置为某些数据,但只要我将线性函数设为负(-m * x b)或给出负启动参数,我就会得到一个值Error . 怎么会这样?

工作代码(但非常糟糕):

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from scipy.optimize import curve_fit
import numpy as np

coeff = np.array([[[0.99686526094349259, 0.97938283953349337, 0.94863615936853296, 0.94854564124775342], [0.96827397528064774, 0.96540665305865092, 0.95427978197668806, 0.95856897574379896], [0.98179629099111465, 0.97186702693950267, 0.95159655933838905, 0.94914854300397633], [0.98405908534322395, 0.96303349070583055, 0.94049529092927575, 0.9388805223880119], [0.9823345791834085, 0.94988298322395981, 0.94432600638572839, 0.94690593392923761], [0.94749073253746852, 0.91026297490006691, 0.90355052302299765, 0.90594713815209094], [0.94666496539970868, 0.92991047096746327, 0.89794751156997354, 0.88308833222256322], [0.95086096977151513, 0.91492190545243046, 0.89878794025327369, 0.8977955699771023], [0.92085169316442461, 0.91020217046939911, 0.88784427604876237, 0.87496086561906938], [0.92584889400513992, 0.90085979379105019, 0.89133459679508531, 0.8616325150553189], [0.89310485081400282, 0.90595436374678995, 0.88127525591336353, 0.86326252690088379], [0.91840500742150677, 0.89454924632418276, 0.86408826887081058, 0.85566354989992877], [0.89798838704263029, 0.8832076831081086, 0.86506489826597432, 0.84337214054453236], [0.88889983668682515, 0.86980848536425781, 0.84371042174678323, 0.83957379021759648], [0.88736216219664954, 0.86926675475222814, 0.85277446531968648, 0.84865506267462365], [0.89663062070888311, 0.86607602443038323, 0.8659545150953607, 0.84029430834919172]], [[0.98470753576416092, 0.96971217002625243, 0.96004611886812241, 0.95478295609420716], [0.97857422516178882, 0.96736740927570075, 0.94170250223897756, 0.93502887988285932], [0.96108325241780046, 0.95765326691101016, 0.93539815321061726, 0.92604301825895496], [0.94587731435279332, 0.92768886024687802, 0.93282077530749263, 0.90535429731870432], [0.90302403377848528, 0.89266000623227681, 0.8692807234190687, 0.87544667565162571], [0.90842678587708314, 0.88666211356287894, 0.86398187968979789, 0.85504438852304376], [0.89752546995523119, 0.88267545460550534, 0.87234425766716139, 0.85876172135527762], [0.89822801432463506, 0.87655235478487536, 0.85584471851158772, 0.85658902361766176], [0.88601822394825691, 0.87395005190159714, 0.83627312926756237, 0.83330154332336259], [0.87884225037341357, 0.88065653329353177, 0.84056204405735102, 0.8401607849719015], [0.89075003483828041, 0.87267764041375551, 0.85244176713643305, 0.83568190241877782], [0.85959060915994512, 0.84803406989175478, 0.84371432488334785, 0.8367409774691672], [0.87852202454848527, 0.86726350147297349, 0.83818563899647958, 0.82938866147454338], [0.89804043662753275, 0.87937066125938534, 0.85151443998090559, 0.82187699186233953], [0.90321780317179479, 0.869062296367767, 0.83728089626607383, 0.83509314955439906], [0.86233285952566208, 0.849027598447326, 0.81563185958519957, 0.79413049278747028]], [[0.9614331304980952, 0.94276836763403404, 0.95224773173387689, 0.94435073432557415], [0.96646444638853402, 0.95169289512912125, 0.94337671204334916, 0.94803267888910381], [0.96611098757791991, 0.96360375171083434, 0.96470576514160444, 0.94484651240282402], [0.97475536616396286, 0.96246556353605883, 0.95381689117327517, 0.94139611761114761], [0.9687660923025867, 0.94859966696407028, 0.93134453209793255, 0.91523213974915074], [0.96375743022156513, 0.94270612998948089, 0.92535089023843731, 0.91900369430775275], [0.94887849034227589, 0.93238747357266238, 0.90554273021270026, 0.88665130565323924], [0.96854119457612831, 0.93254822994869568, 0.91757957859196093, 0.91072927943684312], [0.96094270419351024, 0.94039103897193355, 0.91576864754511167, 0.92371355506927211], [0.94084190749922514, 0.91115539435137249, 0.88412827862448162, 0.88618204421112579], [0.93003355897126139, 0.90939797810425416, 0.89104443138718059, 0.89132735010563013], [0.90555102340603832, 0.89271147136114004, 0.87690138866709455, 0.87137837587447309], [0.93200398659335737, 0.90591867247950508, 0.87354751734735214, 0.87814926743620247], [0.91365812945147296, 0.88981780409716227, 0.88190665467425855, 0.86826167757170658], [0.91141869862588043, 0.90635835796923025, 0.87233896204892503, 0.85353434262799799], [0.89195837829615954, 0.88300374082698796, 0.86748926159856432, 0.86449000226664907]], [[0.96879986856483347, 0.96078007490935335, 0.93950716344560459, 0.92488430078454453], [0.9752456609046477, 0.95774621246952218, 0.94184356900848631, 0.92293860209467038], [0.97065657373100589, 0.95795185233511859, 0.93859661118706295, 0.93202539768815995], [0.94804559142048028, 0.93006649637444039, 0.90771387112998492, 0.90258519884046184], [0.96077108006777256, 0.93048569573051476, 0.91133253827782301, 0.9148863958823249], [0.93860849723734407, 0.91677754219593677, 0.89153677099149176, 0.88976908460093151], [0.93265862156159263, 0.92866167470633953, 0.90696190909565666, 0.89277168267535201], [0.92296813671168709, 0.912224985039783, 0.87781537743834204, 0.87306411003486029], [0.91706712012105851, 0.90403722567106504, 0.8757354170079833, 0.87454171073055964], [0.92709726286042038, 0.91814685823696118, 0.88209201413565719, 0.87071552381815021], [0.91836653505437149, 0.91811646934434055, 0.9001814777254612, 0.89119177051694576], [0.9210885824786097, 0.91154006774147744, 0.89196779567392059, 0.87122730996452769], [0.92479730650932923, 0.90353180550680501, 0.89612926059255604, 0.8759153536185027], [0.93616171066757126, 0.91075016734463399, 0.88885447724252853, 0.88885626714321042], [0.92351264876398886, 0.90903710950245109, 0.88723620200477693, 0.87465600815320343], [0.92037888267316204, 0.89508057275264885, 0.87982783735445902, 0.87559393466446001]], [[0.97011550578127326, 0.95522581736604184, 0.93315192623145238, 0.93944424272962068], [0.94988019701622661, 0.94429908013578179, 0.92576004716017757, 0.91710357586537261], [0.94467022565392866, 0.9229482460189381, 0.92741253607795082, 0.90336279050519641], [0.97132626861718174, 0.94746596833131502, 0.9076094825815042, 0.91288527508638839], [0.95199902391784041, 0.95050488862555038, 0.92973643010482787, 0.90845366420624218], [0.95405326310867389, 0.93427868872098885, 0.91167876117244429, 0.89968868948164438], [0.93857427428164641, 0.93150605269708742, 0.90780371889218081, 0.91036705313234012], [0.93522870621459475, 0.91294797409007766, 0.89414533363003346, 0.88836341562806975], [0.94138132365257743, 0.90816250152409339, 0.88185250825262418, 0.86486337226106458], [0.91508625829121648, 0.90793015669518784, 0.89583048813425947, 0.87621198684565405], [0.90633297396449208, 0.89499118831037805, 0.87850550949117845, 0.86371480286029056], [0.90213998704102139, 0.88056609075844217, 0.85524694184658123, 0.84280735361069925], [0.89897461975500803, 0.87459703492299568, 0.8748773499757786, 0.85762482562168185], [0.89879779579602459, 0.87981668664918256, 0.86340696195704458, 0.86707561188353377], [0.88561185413957633, 0.87922278508857687, 0.86283072658593785, 0.8483337171568931], [0.91395479410421421, 0.89638471340143, 0.86875895133845749, 0.85659213749371366]], [[0.97500001219467169, 0.95662155264479143, 0.96717589138534743, 0.94458286225293919], [0.97517730240293177, 0.95067768286076004, 0.92656748859049209, 0.92673523155886017], [0.96835949798246368, 0.97055429619416234, 0.93699067125268642, 0.91486468224843775], [0.95213221042616913, 0.9632040110721164, 0.9214739279471984, 0.89960240172944927], [0.95073786503207447, 0.93948437302247634, 0.90522596989731774, 0.89326720074878041], [0.94776520396354258, 0.92063089323274516, 0.90605224878254387, 0.91057921323059776], [0.95236694125186316, 0.92632497848432249, 0.91236698644045278, 0.91447083529587925], [0.95299100203256171, 0.91301577950702917, 0.91004624366813003, 0.902179069853698], [0.93556653558997804, 0.91416941278656605, 0.88603182522971402, 0.8901513388950546], [0.9311275490700841, 0.94562892082889594, 0.9074878195121856, 0.88751760656108603], [0.94626572510933116, 0.92350941940795883, 0.90672428944774885, 0.8855709310191755], [0.92865398666382115, 0.92591214681690115, 0.90293990093319565, 0.89295089255515392], [0.9369025837438737, 0.9193931789007489, 0.9110731982857454, 0.91059413248461751], [0.93334790970257286, 0.92206668992859253, 0.92317543068719965, 0.90232362299032121], [0.9398654824049073, 0.91612744661546386, 0.89827645418861213, 0.88996033212717518], [0.92496298279783185, 0.90004617988357472, 0.88184540228383035, 0.87211014521464925]], [[0.96392327212364415, 0.97418561168314199, 0.9512302065349082, 0.93145462657387401], [0.97630040229891679, 0.94495179846314181, 0.9267551292699594, 0.9274361567109809], [0.964898746709276, 0.96313463284142475, 0.94211486984901494, 0.92641924230508965], [0.96533749293631588, 0.95631701333581365, 0.9331371055033808, 0.91902563034589746], [0.96405962017425517, 0.94648094474181099, 0.94009298295037413, 0.91149206935744942], [0.95510976751718646, 0.94511246213550326, 0.93529677151307777, 0.91556932092961396], [0.9543180987584382, 0.93918797237443519, 0.91280751903240898, 0.92915299202936608], [0.94805043080897777, 0.92388997756170166, 0.90863250788835537, 0.90655860106979103], [0.95439605449226317, 0.92001340037452095, 0.8985116348669111, 0.88922729494848107], [0.91541830558733772, 0.91419678582152086, 0.90062503513420877, 0.89492867265114728], [0.92024481782402456, 0.90471951237028525, 0.88751803739336033, 0.87592405011395669], [0.9189924012248345, 0.89536004169359484, 0.88465853867511846, 0.86737904048892334], [0.91292174573389018, 0.87860966785160255, 0.87365876529495334, 0.86495135251092392], [0.90550608925624088, 0.90647839805854524, 0.89309217438160071, 0.87625127085199972], [0.90851503209411766, 0.90329614529779201, 0.8655058924961645, 0.87137934667957839], [0.90146228449063903, 0.88011034919514086, 0.86575265495014009, 0.85321856583961375]], [[0.96135041294278067, 0.9405268802311918, 0.93370459835568143, 0.91238028330744569], [0.9456424876625128, 0.93482953780643085, 0.9229553703255875, 0.9205024843446008], [0.95542958894272678, 0.93006440076283348, 0.91184844644752416, 0.91585811737580303], [0.9339589133806715, 0.9334824043938853, 0.89623037320461685, 0.90212047626841252], [0.94836099605543678, 0.92452300351484418, 0.90613816870579744, 0.92577163834261589], [0.93395975628334871, 0.92377057961787401, 0.90178500929961647, 0.89920273521720573], [0.9437141252299911, 0.91257188741751605, 0.9122407034449358, 0.89542797322808998], [0.94200048624020227, 0.9440695595115961, 0.91703025481256473, 0.8883057640022638], [0.93434864322062627, 0.91208773684721256, 0.88015778693932456, 0.88353134947512535], [0.93043073998538717, 0.903738114210065, 0.88599059811332581, 0.87893332229536625], [0.91872867346576381, 0.90126334364830485, 0.88898969538700745, 0.88125983372795835], [0.89819938332370852, 0.89885664856807179, 0.88697196360384667, 0.88513500732550288], [0.91962865827226481, 0.92031911299892555, 0.88668962985179178, 0.87261483779283811], [0.92816522404819501, 0.90675466731747156, 0.88221205371925926, 0.8739975007130979], [0.93213809200325382, 0.91279840195742745, 0.90598887361049119, 0.88212171578914833], [0.90708415044856505, 0.89147409179524695, 0.86152275473767626, 0.85990979760575104]], [[0.98267385155827003, 0.9397620000886916, 0.93754557355517931, 0.93360345704243342], [0.97204204415350171, 0.94984947712848877, 0.94349384118530466, 0.93537278704197957], [0.95939088442865306, 0.9525349282210539, 0.94429970562460164, 0.92419980773976484], [0.97385586723112116, 0.95170154969308896, 0.92492870491326973, 0.91970226698940694], [0.96154652019554698, 0.95720196221914466, 0.93512768410140168, 0.91516560167884686], [0.96824535607318019, 0.93355609261979833, 0.91986928457484263, 0.91085347141461004], [0.9601646903743678, 0.92726514111086589, 0.92263972275364636, 0.92816070487847757], [0.94312203945702189, 0.92170711619489243, 0.90522474917567897, 0.90100560906090821], [0.94603272157872653, 0.92128944607365404, 0.90539171756897185, 0.90227509989178101], [0.94536876077058385, 0.9197589911416284, 0.91044375068907202, 0.89198262137874318], [0.93725404558537884, 0.90657504507326914, 0.88145931862775639, 0.88448021678361799], [0.93070589916405666, 0.90813023125745407, 0.8673531429254886, 0.8714105337958048], [0.92186759465162227, 0.89867130271177476, 0.87815659820547154, 0.85825249805632076], [0.92163014236017049, 0.88947723853955796, 0.87494377809138923, 0.87504757499997587], [0.91646281480310876, 0.89986372127086789, 0.88652718665040009, 0.86508795194127397], [0.88806536485297272, 0.89521816010687916, 0.85932089051018357, 0.8388112180814048]], [[0.97065524871594389, 0.95342880615874925, 0.94643202931795811, 0.9340626747690689], [0.95825391082937372, 0.94961292828269428, 0.92629058212640092, 0.92086897276698665], [0.95301641493687117, 0.9459133694099604, 0.91503444670375733, 0.91637283051037677], [0.93838859109750872, 0.93210147366414786, 0.92536072959517768, 0.93468045829061486], [0.94181196448927673, 0.94849161262951076, 0.92440239785988376, 0.9100529212500782], [0.93706378887029496, 0.92719231828350268, 0.92696219791976942, 0.92403881332953441], [0.94276785264886909, 0.92778161077908461, 0.9345985287135854, 0.91366013933586077], [0.92820172954700286, 0.93321858598717022, 0.90745509684041714, 0.89804207074149278], [0.96624235239749201, 0.93138689648549366, 0.92595897606326261, 0.89919114722915505], [0.93940373644319652, 0.92450647763394134, 0.91683296988158303, 0.9006066460673906], [0.94976193092110772, 0.90740805468730257, 0.90481338620893459, 0.91000504333055832], [0.92770921589994637, 0.91411986953548541, 0.91157904829335779, 0.89791613813426807], [0.94259125915104724, 0.90006305536927644, 0.90668386601767526, 0.88779585913941916], [0.93658752616019247, 0.92818745480173015, 0.91078473081380718, 0.90344845605780633], [0.93482052805182669, 0.91558459006519333, 0.92295071129581063, 0.89657935975464942], [0.90779566474810969, 0.88759800319587778, 0.86565021337977566, 0.86229179664100231]], [[0.97994751771336841, 0.96467886453753227, 0.94302831972614032, 0.94050532904823936], [0.97303884785912742, 0.95869681277037688, 0.93910501269349445, 0.94408589666731479], [0.97686744730916386, 0.95710112951293025, 0.92937946331975874, 0.9181397015707341], [0.97210902935063515, 0.95416888064261984, 0.94331631928577209, 0.94571133098583449], [0.94132937491444313, 0.93957915000996373, 0.93863449491303785, 0.92865474118066882], [0.94730192349580811, 0.93932539242424273, 0.93662632090649312, 0.91400644685076493], [0.9253768023366874, 0.93317525570411675, 0.92453490457607401, 0.89622894038893397], [0.95224599775738128, 0.92625963931777144, 0.89852133657776456, 0.90012166877835331], [0.92558780038820831, 0.89145648506377428, 0.89630535227419661, 0.87520369825638333], [0.94669445979012978, 0.91244529625254722, 0.89737951554860296, 0.8902427432839275], [0.92212810656081756, 0.90799476768360987, 0.90650159452464973, 0.88859077161196365], [0.9201672498339436, 0.90439965125288357, 0.90126221348511293, 0.90661168414059456], [0.91445414925712787, 0.91563750220959272, 0.8895048650961751, 0.87304247153653147], [0.89961015627504415, 0.89621618902342126, 0.87232947505601688, 0.87539732382104607], [0.91740210451471982, 0.90357136337981414, 0.87886645844561695, 0.86228554504499833], [0.90359884329988793, 0.87081264778519296, 0.84272604691318087, 0.852981305492168]], [[0.98573756315794481, 0.95527015770899293, 0.93371282888197948, 0.92037578571840128], [0.96802260848673682, 0.95652122829451858, 0.93458423303000615, 0.93671798539843343], [0.95086450189134053, 0.93247869372615455, 0.91336906962090258, 0.91782083833437067], [0.94035674691388604, 0.92781537786382806, 0.90708446478209681, 0.91552722071195147], [0.94695044389144045, 0.93497927604100861, 0.91041134892371123, 0.89775253111663278], [0.95190186627859308, 0.92601888653540487, 0.91543716622409277, 0.89191062470862359], [0.93078123475292829, 0.8995241017705613, 0.89100539876460982, 0.89119605991863204], [0.92610645411310111, 0.9122598157847811, 0.89755726287132354, 0.89107572528281387], [0.93414059136911631, 0.90981339717032028, 0.89522970581142702, 0.86750501946138148], [0.93495167034709004, 0.91052259250738898, 0.87387501051986827, 0.87898549633696399], [0.90735776506730892, 0.89288577280999393, 0.90007234990901386, 0.87671558345815015], [0.91041937035886511, 0.89814451067898493, 0.89515766075035319, 0.88305660023716515], [0.91563069205779557, 0.90982679408779521, 0.88452502671728994, 0.88529618724558057], [0.91599427926081001, 0.89465856917104358, 0.87158900797758165, 0.87653649042288539], [0.91916310800702694, 0.8979108031206301, 0.87678398905789157, 0.8722005686342249], [0.87942015160431197, 0.8834477122855755, 0.87219139250342403, 0.85152297132365784]], [[0.98188797353298241, 0.9366239321740556, 0.93122500511857964, 0.92292538590403572], [0.94144209433220993, 0.93555562757467059, 0.92757916571687438, 0.9141665998839994], [0.95119257895702392, 0.93731155227087493, 0.93080050623858346, 0.90554798397968095], [0.94151178559074733, 0.93357662994179647, 0.91106941946687658, 0.90765962592199911], [0.95280916922212755, 0.93791694642341261, 0.93717695207784901, 0.90090401650710661], [0.91912400154247154, 0.89662196942389749, 0.89297659070486946, 0.87658205392873867], [0.90907436739883563, 0.88151897248849553, 0.88918834885571696, 0.8653303276697345], [0.91177958741133003, 0.9020551833815118, 0.87484461163692551, 0.86098417482277978], [0.92250325766988517, 0.88694700537284143, 0.88410427314902795, 0.86857340421788842], [0.91004962493505759, 0.87807750297101494, 0.86958419434971301, 0.87046558615137348], [0.90141122188169431, 0.88943725819796293, 0.8594478400332981, 0.85403613976952086], [0.9181178003859034, 0.88488662664165374, 0.87393510771349459, 0.8620460739263649], [0.91004248817949296, 0.8847819774086878, 0.87166639396939127, 0.8607093993842444], [0.90160020280305309, 0.89829764551548741, 0.87060701787763706, 0.87257547748054642], [0.87820842846161895, 0.87739970502697107, 0.87856257893771306, 0.86695649122175444], [0.89852161379486206, 0.88159969240740788, 0.84770784564505053, 0.85769611124739542]], [[0.96869482726760392, 0.96353897217046625, 0.93616658952012444, 0.91682688037294335], [0.95993615891078299, 0.94430960470579206, 0.90700786674962453, 0.90521642097712574], [0.94128351220688511, 0.93197529520037936, 0.91724766309672112, 0.90294000148796838], [0.93681377122867426, 0.92251302407975666, 0.89865362095896828, 0.87451439342885651], [0.9433534430357613, 0.92124418213207404, 0.90743224907774878, 0.90992390514606003], [0.93864374137934481, 0.92649899283294634, 0.90751598253809307, 0.89342546686470559], [0.92509838204204431, 0.92359795689788782, 0.9071665884850374, 0.88881858511536294], [0.9186528110896226, 0.90516803184113803, 0.89652012781541601, 0.88687511785284034], [0.91307623763837109, 0.89727397709859613, 0.89702405028793453, 0.89135331660806749], [0.916413904441718, 0.89682256171988728, 0.88390819413304844, 0.8907398141684657], [0.92015330488071723, 0.91251304748935136, 0.91036755690265214, 0.89604867053444071], [0.93244190523520765, 0.89916875271957197, 0.89750515368542705, 0.88772055936022665], [0.92331934219734357, 0.91116468175350773, 0.90893906620935139, 0.90128562933010081], [0.93705499055179453, 0.91973405672291364, 0.90614772721961234, 0.87934137764434495], [0.93987349284312749, 0.92124008594182305, 0.90728170765428506, 0.8859402142927757], [0.88102270446766817, 0.84426048025825207, 0.85621931486440173, 0.85409240073310733]], [[0.96663584664133917, 0.96142001374558606, 0.93073305763312608, 0.92700835965180728], [0.96450177098156031, 0.92088630142292804, 0.92348876990707585, 0.91053977573412215], [0.95480376406204159, 0.94921251258503336, 0.92773007461967172, 0.90751720837184369], [0.95506591302509947, 0.93752594112741316, 0.93167130632146411, 0.9122868216848794], [0.93593051329299293, 0.93275691413563333, 0.90259645472695393, 0.89832500641083146], [0.94595454483091179, 0.9255314659042857, 0.89753318528923631, 0.86856248925519697], [0.91977547908918145, 0.89828952115617189, 0.89864898389538006, 0.89045243338547164], [0.92407382954283313, 0.89919131571961397, 0.88429418334035437, 0.86977651586633065], [0.90205630572236506, 0.88497160827342347, 0.86575358298004523, 0.86183579789151077], [0.90435501087207992, 0.87022955191064, 0.87514359412811604, 0.86079415103046075], [0.90031762639692525, 0.88618617428506652, 0.88653264217181926, 0.8641812783080256], [0.90574750075197286, 0.88073221607654084, 0.87640304635829203, 0.87151752581692921], [0.89727748683954212, 0.87997577045465769, 0.86381708534013213, 0.8562651666546216], [0.90677734269038424, 0.87697734880721434, 0.86094011004693394, 0.84636567420897835], [0.91589906274823318, 0.88133691136687498, 0.87418242613932162, 0.86431133085914291], [0.89574642711765184, 0.87357485258400447, 0.8622218225340631, 0.85573181626965833]], [[0.9723625523525754, 0.93878144925013052, 0.92763069908394691, 0.91669392031348362], [0.95775139599875636, 0.96113772039458967, 0.94654705456907617, 0.93447603150314495], [0.97005393964194786, 0.95089713398313647, 0.94938577180946571, 0.94069492298542012], [0.95003405318298817, 0.93066410804286781, 0.94200831216004843, 0.92494701816436764], [0.96182554879689985, 0.94281654703535123, 0.92705597586145339, 0.93031328707137884], [0.93807943123336146, 0.92938051475328287, 0.90488874751990633, 0.90069596831080934], [0.93226464362035899, 0.93395961873233191, 0.91044668454707345, 0.89862578021469086], [0.92592514865144071, 0.9249579439660085, 0.91705130471309904, 0.89963303749296752], [0.94971097528067405, 0.92080056735161908, 0.90097748880507655, 0.90401963834449095], [0.94174371698415038, 0.92298503426915368, 0.91504856797725698, 0.89707418098941283], [0.94534599949029197, 0.9212818734165662, 0.90339447405147066, 0.91469628584989215], [0.93947719162376486, 0.92983114592091132, 0.90085073230452062, 0.8876632168361035], [0.95313065491690452, 0.91041199061012923, 0.88959793662960918, 0.90118023403235892], [0.935269872380733, 0.93321055929262442, 0.91872198114099235, 0.89460383867534654], [0.93193583237639099, 0.92584474498566616, 0.89550540121336775, 0.88277689841129969], [0.8915390291810289, 0.90381974357688288, 0.87586457325063538, 0.87600839259287067]]])

def linfunc(x, m, b):
    return m*x+b

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

colors = ["red", "green", "blue", "black", "purple","red", "green", "blue", "black", "purple","red", "green", "blue", "black", "purple", "orange"]
markers = ["o", "o", "o", "o", "o", "^", "^", "^", "^", "^", "x", "x", "x", "x", "x", "x"]
cX = []
cY = []
cZ = []
for obstacle in range(16):
    time = 3    
    for molecule in range(16):        
        cX.append(obstacle)
        cY.append(molecule)
        cZ.append(coeff[obstacle][molecule][time])    
    popt, pcov = curve_fit(linfunc, cY, cZ, p0=[1, 1])    
    ax.plot(cX, cY, cZ)
    ax.plot(cX, cY, linfunc(cY, *popt), ls="-")    
    cX = []
    cY = []
    cZ = []
ax.set_xlabel('obstacles')
ax.set_ylabel('molecules')
plt.show()

这个产生ValueError:操作数不能与形状(0)一起广播(16)

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from scipy.optimize import curve_fit
import numpy as np

coeff = same as above

def linfunc(x, m, b):
    return m*x+b

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

colors = ["red", "green", "blue", "black", "purple","red", "green", "blue", "black", "purple","red", "green", "blue", "black", "purple", "orange"]
markers = ["o", "o", "o", "o", "o", "^", "^", "^", "^", "^", "x", "x", "x", "x", "x", "x"]
cX = []
cY = []
cZ = []
for obstacle in range(16):
    time = 3    
    for molecule in range(16):        
        cX.append(obstacle)
        cY.append(molecule)
        cZ.append(coeff[obstacle][molecule][time])    
    popt, pcov = curve_fit(linfunc, cY, cZ, p0=[-1, 1]) #note it's negative one here
    ax.plot(cX, cY, cZ)
    ax.plot(cX, cY, linfunc(cY, *popt), ls="-")    
    cX = []
    cY = []
    cZ = []
ax.set_xlabel('obstacles')
ax.set_ylabel('molecules')
plt.show()

编辑:完整的错误消息:

文件"coeff.py",第32行,在popt中,pcov = curve_fit(linfunc,cY,cZ,p0 = [ - 11,1])
文件"/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py",第434行,在curve_fit中res = leastsq(func,p0,args = args,full_output = 1,** kw)文件"/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py",第276行,至少为m = _check_func('leastsq','func',func,x0,args, n)[0]文件"/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py",第13行,在_check_func res = atleast_1d(thefunc(((x0 [:numinputs],)args)))文件"/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py",第346行,在_general_function返回函数中(xdata, params) - ydata ValueError:操作数无法与形状一起广播(0)(16)