Transform xyz data into surface for Plotly

Viewed 125

I have a text file with xyz data called elevation.txt.

29.6615067663688    -98.3933654143067   -0.772875302700243
29.6615067663688    -98.3933757636723   -0.71250410914962
29.6615065076668    -98.3933654143067   -0.757068728178126
29.6615032793597    -98.3933757636723   -0.761051993140882
29.6615067663688    -98.3933647490732   -0.762067716839908
29.6615067663688    -98.3933861130379   -0.6694827930163
29.6615039261939    -98.3933861130379   -0.700458102119342
29.6615067663688    -98.3933964624035   -0.616901857503478
29.661506592754 -98.3933964624035   -0.616901857503478
29.6615067663688    -98.3933969253778   -0.624557146812265
29.6615157595849    -98.3933447155754   -0.765732910338727
29.6615157595849    -98.393355064941    -0.70790301178198
29.6615151056918    -98.3933447155754   -0.764905434184072
29.66151057784  -98.393355064941    -0.775122479690196
29.6615157595849    -98.3933432209641   -0.769340655884378
29.6615157595849    -98.3933654143067   -0.65363454400682
29.6615157595849    -98.3933757636723   -0.607481276569502
29.6615157595849    -98.3933861130379   -0.576043135792759
29.6615157595849    -98.3933964624035   -0.562651209935325
29.6615157595849    -98.3934068117692   -0.574109217270234
29.6615106655842    -98.3934068117692   -0.614824188539728
29.6615157595849    -98.3934151474394   -0.590072189764953
29.6615247528009    -98.3933240168442   -0.716696572671196
29.6615247528009    -98.3933343662098   -0.686067695192037
29.661524433825 -98.3933240168442   -0.716696572671196
29.6615197295622    -98.3933343662098   -0.756041264529586
29.6615247528009    -98.393323315098    -0.727161408607287
29.6615247528009    -98.3933447155754   -0.638302943876681
29.6615247528009    -98.393355064941    -0.595028363722974
29.6615247528009    -98.3933654143067   -0.556618694163944
29.6615247528009    -98.3933757636723   -0.524177330077976
29.6615247528009    -98.3933861130379   -0.502490718796878
29.6615247528009    -98.3933964624035   -0.493857409456894
29.6615247528009    -98.3934068117692   -0.504201213967065
29.6615247528009    -98.3934171611348   -0.537894228748428
29.6615169901716    -98.3934171611348   -0.583259938640822
29.6615247528009    -98.3934272247451   -0.553953638867654
29.661533746017 -98.3933136674785   -0.65337903725532
29.661533746017 -98.3933240168442   -0.606100909015026
29.6615302013555    -98.3933136674785   -0.708003376811007
29.661533746017 -98.3933086036904   -0.674403153398373
29.661533746017 -98.3933343662098   -0.567366118147447
29.661533746017 -98.3933447155754   -0.534873445625749
29.661533746017 -98.393355064941    -0.508345134300043
29.661533746017 -98.3933654143067   -0.4861347257239
29.661533746017 -98.3933757636723   -0.467501455070533
29.661533746017 -98.3933861130379   -0.454825455237369
29.661533746017 -98.3933964624035   -0.450999899418036
29.661533746017 -98.3934068117692   -0.460597462045143
29.661533746017 -98.3934171611348   -0.485507380618685
29.661533746017 -98.3934275105004   -0.527974722804913
29.661525070305 -98.3934275105004   -0.556840681625602
29.661533746017 -98.3934344310752   -0.562287963820779
29.6615427392331    -98.3933033181129   -0.573540650163409
29.6615427392331    -98.3933136674785   -0.534670699160301
29.6615374459315    -98.3933033181129   -0.636710444804976
29.6615427392331    -98.393296254736    -0.60161550624673
29.6615427392331    -98.3933240168442   -0.504091160067674
29.6615427392331    -98.3933343662098   -0.481685184127628
29.6615427392331    -98.3933447155754   -0.464099499361851
29.6615427392331    -98.393355064941    -0.451925941678382
29.6615427392331    -98.3933654143067   -0.442387452656249
29.6615427392331    -98.3933757636723   -0.434505319003051
29.6615427392331    -98.3933861130379   -0.43005283413379
29.6615427392331    -98.3933964624035   -0.430975358433614
29.6615427392331    -98.3934068117692   -0.439570957852027
29.6615427392331    -98.3934171611348   -0.457793169386434
29.6615427392331    -98.3934275105004   -0.486800614061849
29.6615427392331    -98.393437859866    -0.526190392944102
29.6615399177873    -98.393437859866    -0.537130143062313
29.6615427392331    -98.3934387004372   -0.514852475111695
29.6615517324491    -98.3932929687473   -0.505021052994948
29.6615517324491    -98.3933033181129   -0.473109594469918
29.6615456966351    -98.3932929687473   -0.575492082966775
29.6615517324491    -98.3932864360227   -0.521250369085692
29.6615517324491    -98.3933136674785   -0.45228220458921
29.6615517324491    -98.3933240168442   -0.437672906029206
29.6615517324491    -98.3933343662098   -0.428764266490191
29.6615517324491    -98.3933447155754   -0.423388509125061
29.6615517324491    -98.393355064941    -0.42064725625545
29.6615517324491    -98.3933654143067   -0.42059184404286
29.6615517324491    -98.3933757636723   -0.421243310930151
29.6615517324491    -98.3933861130379   -0.423173771259656
29.6615517324491    -98.3933964624035   -0.428077085966038
29.6615517324491    -98.3934068117692   -0.436455120482265
29.6615517324491    -98.3934171611348   -0.449453737366639
29.6615517324491    -98.3934275105004   -0.467176208307023
29.6615517324491    -98.393437859866    -0.491158847783368
29.6615517324491    -98.3934410558634   -0.497183097610673
29.6615607256652    -98.3932826193817   -0.448472127921775
29.6615607256652    -98.3932929687473   -0.423026080899604
29.6615555491089    -98.3932826193817   -0.489444421659471
29.6615607256652    -98.3932774428508   -0.459300103364114
29.6615607256652    -98.3933033181129   -0.41007264067008
29.6615607256652    -98.3933136674785   -0.403379653580657
29.6615607256652    -98.3933240168442   -0.40160597586771
29.6615607256652    -98.3933343662098   -0.402303299508787
29.6615607256652    -98.3933447155754   -0.405026619865623
29.6615607256652    -98.393355064941    -0.409214051179902
29.6615607256652    -98.3933654143067   -0.415145859438724
29.6615607256652    -98.3933757636723   -0.421400604537439
29.6615607256652    -98.3933861130379   -0.428143788263469
29.6615607256652    -98.3933964624035   -0.436987817589795
29.6615607256652    -98.3934068117692   -0.44512400629128
29.6615607256652    -98.3934171611348   -0.454197381772929
29.6615607256652    -98.3934275105004   -0.463704639044295
29.6615607256652    -98.393437859866    -0.475074798026128
29.6615607256652    -98.3934419552231   -0.47966411974312
29.6615697188812    -98.393272270016    -0.406872175697117
29.6615697188812    -98.3932826193817   -0.381486406072099
29.6615665050732    -98.393272270016    -0.423858240303332
29.6615697188812    -98.3932696405537   -0.408051452734071
29.6615697188812    -98.3932929687473   -0.37507324528184
29.6615697188812    -98.3933033181129   -0.376443590970155
29.6615697188812    -98.3933136674785   -0.381102967001596
29.6615697188812    -98.3933240168442   -0.387274655391025
29.6615697188812    -98.3933343662098   -0.39395895958836
29.6615697188812    -98.3933447155754   -0.402001773351628
29.6615697188812    -98.393355064941    -0.410521732197196
29.6615697188812    -98.3933654143067   -0.42095882320541
29.6615697188812    -98.3933757636723   -0.430973881383409
29.6615697188812    -98.3933861130379   -0.441647395592099
29.6615697188812    -98.3933964624035   -0.452005925774586
29.6615697188812    -98.3934068117692   -0.461284006552319
29.6615697188812    -98.3934171611348   -0.467917848494494
29.6615697188812    -98.3934275105004   -0.471415514054002
29.6615697188812    -98.393437859866    -0.473245094507774
29.6615697188812    -98.3934419996021   -0.472659420054981
29.6615787120973    -98.393272270016    -0.355651132143748
29.6615787120973    -98.3932826193817   -0.347239308692565
29.6615787120973    -98.3932632737198   -0.35591381410751
29.6615787120973    -98.3932929687473   -0.35162619014784
29.6615787120973    -98.3933033181129   -0.361200636616275
29.6615787120973    -98.3933136674785   -0.371593174544898
29.6615787120973    -98.3933240168442   -0.382765752356477
29.6615787120973    -98.3933343662098   -0.395095946884567
29.6615787120973    -98.3933447155754   -0.407420962025753
29.6615787120973    -98.393355064941    -0.420616003396162
29.6615787120973    -98.3933654143067   -0.434115117961653
29.6615787120973    -98.3933757636723   -0.447571228535537
29.6615787120973    -98.3933861130379   -0.460083111502854
29.6615787120973    -98.3933964624035   -0.471282501279632
29.6615787120973    -98.3934068117692   -0.479825008942328
29.6615787120973    -98.3934171611348   -0.483889960099589
29.6615787120973    -98.3934275105004   -0.483803486838212
29.6615787120973    -98.393437859866    -0.479388198273796
29.6615787120973    -98.3934408449891   -0.478342909984406
29.6615877053134    -98.3932619206504   -0.352953163198265
29.6615877053134    -98.393272270016    -0.330661192674995
29.661580967234 -98.3932619206504   -0.367248936850558

I read the data using

elevation =  np.loadtxt('elevation.txt')
x, y, z = elevation[:, 0], elevation[:, 1], elevation[:, 2]

Because each z point is an unique combination of the corresponding x and y point, they all have the same length, 150. I want to post this surface using plotly, not matplotlib. Their documentation says the following:

The data the describes the coordinates of the surface is set in z. Data in z should be a 2D list. Coordinates in x and y can either be 1D lists or 2D lists (e.g. to graph parametric surfaces).

However, the shape of z is equal to

 (150, )

It needs to be equal to

 (150, 150)

How can I achieve this?

1 Answers

The Surface class expects the points to be spaced linearly across both x and y (like those that would be created by np.linspace, examples here). It appears that your data is a set of 3d points which are not linearly spaced out in a grid as Surface expects.

Perhaps a better solution would be to build a 3d scatter plot, or a 3d mesh.

Related