使用“matplotlib.mlab.griddata”时程序挂起

2023-12-12

我编写了一个脚本(Python 2.6)来以 x,y,z (.csv 格式)网格数据,并显示数据的等高线图。

该脚本适用于某些数据集,但不适用于其他数据集 - 即使这两个数据集是使用相同的脚本创建的。

要绘制的数据集是通过对主数据集进行二次采样而创建的。

以下是 every_4.csv 的示例(每 4 行对主数据集进行二次采样)。

Easting Northing    TMI_nT 
526243.0    5254128.9   62278.8
526259.4    5254128.9   62352.3
526275.9    5254128.9   62303.3
526292.3    5254128.9   62361.9
526308.8    5254128.9   62667.8
526325.2    5254128.9   62668.6
526341.7    5254128.9   61700.1
526358.1    5254128.9   62029.6
526374.6    5254128.9   62042.7

使用我的脚本可以正确绘制该数据。

“every_3.csv”与 every_4.csv 的形式相同,导致我的脚本在尝试执行时挂起(没有错误消息):

zi = 网格数据(x, y, z, xi, yi)

这是我正在使用的脚本:

### program to test gridding and contouring

import numpy as N
import scipy as S
from matplotlib.mlab import griddata
import matplotlib.pyplot as P
import matplotlib.cm as CM

longarray = N.loadtxt('every_3.csv', skiprows=1, delimiter=',')
x = longarray[:,0]
y = longarray[:,1]
z = longarray[:,2]

max_x = max(x)
min_x = min(x)
max_y = max(y)
min_y = min(y)

##print max_y
##print min_x
##print max_x
##print min_y

xi = N.linspace(min_x, max_x)
yi = N.linspace(min_y, max_y)

zi = griddata(x, y, z, xi, yi)
print zi
CS = P.contourf(xi,yi,zi,15,cmap=CM.RdYlBu)

P.show()

我无法弄清楚为什么这个脚本对于某些文件而挂起,而对于其他文件却挂起。

注意:如果我在 Excel 中打开 every_3.csv 并删除一些行(例如文件中 50% 的行),我可以让脚本运行...

Update

这是一个更完整的数据集:

Easting Northing    TMI_nT
526243  5254128.9   62278.8
526247.1    5254128.9   62413.3
526251.2    5254128.9   62398.6
526255.3    5254128.9   62355.7
526259.4    5254128.9   62352.3
526263.6    5254128.9   62327.8
526267.7    5254128.9   62279.6
526271.8    5254128.9   62322.1
526275.9    5254128.9   62303.3
526280  5254128.9   62375.1
526284.1    5254128.9   62561.4
526288.2    5254128.9   62302.4
526292.3    5254128.9   62361.9
526374.6    5254128.9   62042.7
526378.7    5254128.9   62139.6
526382.8    5254128.9   61891.5
526386.9    5254128.9   61937.2
526391  5254128.9   62238.7
526395.1    5254128.9   62344.9
526399.2    5254128.9   62220.4
526403.3    5254128.9   62027
526407.4    5254128.9   62392.2
526411.6    5254128.9   63252.4
526415.7    5254128.9   62951.8
526419.8    5254128.9   62504.5
526423.9    5254128.9   62927.6
526428  5254128.9   62813.9
526432.1    5254128.9   63381.4
526436.2    5254128.9   63458.5
526440.3    5254128.9   63273
526444.4    5254128.9   62945
526448.6    5254128.9   62466.2
526452.7    5254128.9   62300.3
526456.8    5254128.9   62164.3
526460.9    5254128.9   62144.7
526465  5254128.9   62216.7
526469.1    5254128.9   62307.3
526473.2    5254128.9   62437.6
526477.3    5254128.9   62495
526481.4    5254128.9   62256.1
526485.6    5254128.9   61951.2
526489.7    5254128.9   61632
526493.8    5254128.9   61221.6
526497.9    5254128.9   62414.3
526502  5254128.9   64152.7
526506.1    5254128.9   61964.7
526510.2    5254128.9   61952.5
526514.3    5254128.9   62104.2
526518.4    5254128.9   62190.4
526522.6    5254128.9   62334.8
526526.7    5254128.9   62468.8
526530.8    5254128.9   62437.3
526296.4    5253951.8   62138
526300.6    5253951.8   62283.3
526304.7    5253951.8   62336
526308.8    5253951.8   62367.6
526312.9    5253951.8   62416
526317  5253951.8   62395.3
526321.1    5253951.8   62364.1
526325.2    5253951.8   62363.2
526329.3    5253951.8   62292.6
526333.4    5253951.8   62252
526337.6    5253951.8   62179.1
526341.7    5253951.8   62086.8
526345.8    5253951.8   62069.6
526349.9    5253951.8   62108.4
526354  5253951.8   61994
526358.1    5253951.8   61909.1
526362.2    5253951.8   61943.1
526366.3    5253951.8   61918.6
526370.4    5253951.8   61895.9
526374.6    5253951.8   61871.6
526378.7    5253951.8   61821.4
526382.8    5253951.8   61778.1
526386.9    5253951.8   61738.2
526391  5253951.8   61644.5
526395.1    5253951.8   61555.8
526399.2    5253951.8   61540
526403.3    5253951.8   61549.6
526407.4    5253951.8   61596.4
526411.6    5253951.8   61566.5
526415.7    5253951.8   61565.1
526419.8    5253951.8   61287.6
526423.9    5253951.8   61368
526428  5253951.8   61481.5
526432.1    5253951.8   61228.8
526436.2    5253951.8   61024.6
526440.3    5253951.8   60960.9
526444.4    5253951.8   61146.7
526448.6    5253951.8   61240.8
526452.7    5253951.8   61396.5
526456.8    5253951.8   61536.9
526460.9    5253951.8   61677.1
526465  5253951.8   61715.6
526469.1    5253951.8   61749.8
526473.2    5253951.8   61809.1
526477.3    5253951.8   61939.2
526481.4    5253951.8   61913.3
526485.6    5253951.8   62035.7
526489.7    5253951.8   62108.9
526493.8    5253951.8   62025.4
526497.9    5253951.8   61929.1
526502  5253951.8   61947.2
526506.1    5253951.8   62182.8
526510.2    5253951.8   62239.3
526514.3    5253951.8   62071.7
526518.4    5253951.8   62054.5
526522.6    5253951.8   62001.3
526526.7    5253951.8   61993.5
526530.8    5253951.8   62009.3
526534.9    5253951.8   61966.5
526539  5253951.8   61947.2
526543.1    5253951.8   61936.4
526547.2    5253951.8   61974
526551.3    5253951.8   62023.6
526555.4    5253951.8   62068.7
526559.6    5253951.8   62096.1
526563.7    5253951.8   62113.4
526567.8    5253951.8   62085.1
526571.9    5253951.8   62100.7
526576  5253951.8   62180.1
526580.1    5253951.8   62231.8
526584.2    5253951.8   62142.9
526588.3    5253951.8   62137.1
526592.4    5253951.8   62135.4
526596.6    5253951.8   62118.5
526600.7    5253951.8   62104.9
526604.8    5253951.8   62126.5
526608.9    5253951.8   62129.7
526613  5253951.8   62127
526617.1    5253951.8   62122.8
526621.2    5253951.8   62091.5
526625.3    5253951.8   62143.7
526629.4    5253951.8   62144.2
526633.6    5253951.8   62148.1
526637.7    5253951.8   62145.6
526641.8    5253951.8   62247.1
526645.9    5253951.8   62267.5
526650  5253951.8   62131.8
526243  5253955.9   62073.3
526247.1    5253955.9   62018.5
526251.2    5253955.9   61948.4
526255.3    5253955.9   61965.1
526259.4    5253955.9   61980.3
526263.6    5253955.9   61982.2
526267.7    5253955.9   61985.3
526271.8    5253955.9   61979.6
526275.9    5253955.9   61999.4
526280  5253955.9   62025.7
526284.1    5253955.9   62064.8
526288.2    5253955.9   62068.6
526292.3    5253955.9   62099.2
526296.4    5253955.9   62172.6
526300.6    5253955.9   62283.8
526304.7    5253955.9   62440.8
526308.8    5253955.9   62458.1
526312.9    5253955.9   62588.3
526317  5253955.9   62521.1
526321.1    5253955.9   62390.8
526325.2    5253955.9   62310.4
526329.3    5253955.9   62271
526333.4    5253955.9   62214.3
526337.6    5253955.9   62118.8
526341.7    5253955.9   62024.5
526345.8    5253955.9   61989.4
526349.9    5253955.9   61943.5
526354  5253955.9   61835.8

526506.1    5253955.9   61915.8
526510.2    5253955.9   62043
526514.3    5253955.9   62039.2
526518.4    5253955.9   62021.1
526522.6    5253955.9   62014
526526.7    5253955.9   61930.3
526530.8    5253955.9   61880.7
526534.9    5253955.9   61758.4
526539  5253955.9   61733.5
526543.1    5253955.9   61787.5
526547.2    5253955.9   61862.6
526551.3    5253955.9   61934.6
526555.4    5253955.9   61990.5
526559.6    5253955.9   62059.5
526563.7    5253955.9   62092
526567.8    5253955.9   62104.3
526571.9    5253955.9   62146.3
526576  5253955.9   62242.9
526580.1    5253955.9   62420.5
526584.2    5253955.9   62204.1
526588.3    5253955.9   62178.4
526592.4    5253955.9   62159
526596.6    5253955.9   62147.1
526600.7    5253955.9   62159.6
526604.8    5253955.9   62144.3
526608.9    5253955.9   62131.1
526613  5253955.9   62121.7
526617.1    5253955.9   62117.9
526621.2    5253955.9   62084.7
526625.3    5253955.9   62139.2
526629.4    5253955.9   62136.5
526633.6    5253955.9   62142
526637.7    5253955.9   62144.3
526641.8    5253955.9   62250.2
526645.9    5253955.9   62274.5
526650  5253955.9   62119
526243  5253960 62104
526247.1    5253960 62041.8
526251.2    5253960 61978.7
526255.3    5253960 61993.8
526259.4    5253960 61998.6
526263.6    5253960 61981
526267.7    5253960 61982
526271.8    5253960 61995.3
526275.9    5253960 62010.1
526280  5253960 62030.7
526284.1    5253960 62061.3
526288.2    5253960 62089.9
526292.3    5253960 62115.6
526296.4    5253960 62205.4
526300.6    5253960 62319.9
526304.7    5253960 62392.1
526308.8    5253960 62434.8
526312.9    5253960 62466.7
526317  5253960 62479.9
526321.1    5253960 62358.1
526325.2    5253960 62281.7
526329.3    5253960 62214.8
526333.4    5253960 62131.9
526382.8    5253960 61613.3
526386.9    5253960 61591.6
526391  5253960 61406.2
526395.1    5253960 61179.4
526399.2    5253960 61291.8
526403.3    5253960 61307.2
526407.4    5253960 61304.3
526411.6    5253960 61320.5
526415.7    5253960 61376.8
526419.8    5253960 61160.5
526423.9    5253960 61045.8
526428  5253960 61138.2
526432.1    5253960 61113.1
526436.2    5253960 60926.6
526440.3    5253960 60793.8
526444.4    5253960 60775.6
526448.6    5253960 60776.9
526452.7    5253960 60979.6
526456.8    5253960 61309.1
526460.9    5253960 61772.9
526465  5253960 61665.1
526469.1    5253960 61554.1
526473.2    5253960 61569.5
526477.3    5253960 61725.2
526481.4    5253960 61846
526485.6    5253960 61948.4
526489.7    5253960 61944.3
526493.8    5253960 61848
526497.9    5253960 61677.3
526502  5253960 61516.1
526506.1    5253960 61634.4
526510.2    5253960 61884.9
526514.3    5253960 61975.8
526518.4    5253960 61909.8
526522.6    5253960 61905.6
526526.7    5253960 61835
526530.8    5253960 61692.3
526534.9    5253960 61408.4
526539  5253960 61533.9
526543.1    5253960 61670.4
526547.2    5253960 61785.9
526551.3    5253960 61878.6
526555.4    5253960 61963.3
526559.6    5253960 62048.6
526563.7    5253960 62070.7
526567.8    5253960 62099.5
526571.9    5253960 62140.9
526576  5253960 62242.6
526580.1    5253960 62255
526584.2    5253960 62171.5
526588.3    5253960 62180.7
526592.4    5253960 62164.1
526596.6    5253960 62158.9
526600.7    5253960 62147.7
526604.8    5253960 62146.6
526608.9    5253960 62129
526613  5253960 62122.5
526617.1    5253960 62114.6
526621.2    5253960 62080.8
526625.3    5253960 62140.4
526629.4    5253960 62142.5
526633.6    5253960 62149.3
526637.7    5253960 62152
526641.8    5253960 62263.4
526645.9    5253960 62291.9
526650  5253960 62286.3
526243  5253964.1   62092
526247.1    5253964.1   62041.8
526251.2    5253964.1   61978.3
526255.3    5253964.1   62000.1
526259.4    5253964.1   62012.2
526263.6    5253964.1   62027.1
526267.7    5253964.1   62001.6
526271.8    5253964.1   62003.2
526275.9    5253964.1   61988.3
526280  5253964.1   62028.8
526284.1    5253964.1   62056.9
526288.2    5253964.1   62075.6
526292.3    5253964.1   62149.4
526296.4    5253964.1   62248
526300.6    5253964.1   62365.5
526555.4    5253964.1   61980.9
526559.6    5253964.1   62035.4
526563.7    5253964.1   62055.7
526567.8    5253964.1   62100.7
526571.9    5253964.1   62146.3
526576  5253964.1   62199
526580.1    5253964.1   62195.8
526584.2    5253964.1   62152.1
526588.3    5253964.1   62147.5
526592.4    5253964.1   62192.7
526596.6    5253964.1   62123.1
526600.7    5253964.1   62114
526604.8    5253964.1   62115.9
526608.9    5253964.1   62108.7
526613  5253964.1   62106.3
526617.1    5253964.1   62101.6
526621.2    5253964.1   62065.8
526625.3    5253964.1   62131
526629.4    5253964.1   62133.5
526633.6    5253964.1   62139.8
526637.7    5253964.1   62143
526641.8    5253964.1   62245.9
526645.9    5253964.1   62265.8
526650  5253964.1   62302.6
526243  5253968.3   62086
526247.1    5253968.3   62035.9
526251.2    5253968.3   61980
526255.3    5253968.3   61995.1
526259.4    5253968.3   62021.7
526263.6    5253968.3   62012.6
526267.7    5253968.3   61992.3
526271.8    5253968.3   62024.4
526275.9    5253968.3   61968.1
526280  5253968.3   62030.8
526284.1    5253968.3   62045.5
526288.2    5253968.3   62092.9
526292.3    5253968.3   62189.2
526296.4    5253968.3   62316.8
526300.6    5253968.3   62476.9
526304.7    5253968.3   62513.2
526308.8    5253968.3   62437.8
526312.9    5253968.3   62356.8
526317  5253968.3   62305.8
526321.1    5253968.3   62248.8
526325.2    5253968.3   62187.3
526329.3    5253968.3   62115.2
526333.4    5253968.3   62031
526337.6    5253968.3   62028.7
526341.7    5253968.3   61980.8
526345.8    5253968.3   61979.9
526349.9    5253968.3   61825.2
526354  5253968.3   61721.9
526358.1    5253968.3   61733.8
526362.2    5253968.3   61654.4
526366.3    5253968.3   61493.2
526370.4    5253968.3   61363.9
526374.6    5253968.3   61270.6
526378.7    5253968.3   61302.3
526382.8    5253968.3   61352.9
526386.9    5253968.3   61309
526391  5253968.3   61151.5
526395.1    5253968.3   60971.2
526399.2    5253968.3   60867.7
526403.3    5253968.3   60888.3
526407.4    5253968.3   60935
526411.6    5253968.3   60938.5
526415.7    5253968.3   61003.7
526419.8    5253968.3   61103.4
526423.9    5253968.3   60876.9
526428  5253968.3   60551.8
526432.1    5253968.3   60572.6
526436.2    5253968.3   60717
526440.3    5253968.3   60755.9
526444.4    5253968.3   60572.4
526448.6    5253968.3   60121.9
526563.7    5253968.3   62039.3
526567.8    5253968.3   62088.7
526571.9    5253968.3   62134.1
526576  5253968.3   62154.3
526580.1    5253968.3   62181.4
526584.2    5253968.3   62209.6
526588.3    5253968.3   62200.7
526592.4    5253968.3   62210.8
526596.6    5253968.3   62184.9
526600.7    5253968.3   62175.3
526604.8    5253968.3   62120.9
526608.9    5253968.3   62105.4
526613  5253968.3   62100.4
526617.1    5253968.3   62089.4
526621.2    5253968.3   62048.4
526625.3    5253968.3   62109.9
526629.4    5253968.3   62118.6
526633.6    5253968.3   62114.2
526637.7    5253968.3   62122.6
526641.8    5253968.3   62244.9
526645.9    5253968.3   62267.5
526650  5253968.3   62310.7
526243  5253972.4   62069.2
526247.1    5253972.4   62038.8
526251.2    5253972.4   62000.6
526255.3    5253972.4   62021.2
526259.4    5253972.4   62007
526263.6    5253972.4   62003.1
526267.7    5253972.4   62021.6
526271.8    5253972.4   62052.7
526275.9    5253972.4   62073.4
526280  5253972.4   62056.2
526284.1    5253972.4   62089.7
526288.2    5253972.4   62148.2
526292.3    5253972.4   62244.1
526296.4    5253972.4   62372
526300.6    5253972.4   62451.7
526304.7    5253972.4   62476
526308.8    5253972.4   62392.1
526312.9    5253972.4   62354.4
526317  5253972.4   62276.2
526321.1    5253972.4   62209.1
526325.2    5253972.4   62164.2
526329.3    5253972.4   62089.1
526333.4    5253972.4   62038.1
526337.6    5253972.4   61983.1
526341.7    5253972.4   61910.2
526345.8    5253972.4   61794.9
526349.9    5253972.4   61654
526354  5253972.4   61547
526358.1    5253972.4   61532.1
526362.2    5253972.4   61464.3
526366.3    5253972.4   61343.5
526370.4    5253972.4   61173
526374.6    5253972.4   61061.3
526378.7    5253972.4   61041.7
526382.8    5253972.4   61234.2
526386.9    5253972.4   61196.5
526391  5253972.4   61047.1
526395.1    5253972.4   60856.4
526399.2    5253972.4   60764.9
526403.3    5253972.4   60778.6
526407.4    5253972.4   60836.6
526411.6    5253972.4   60887.4
526415.7    5253972.4   61012
526419.8    5253972.4   61134.9
526423.9    5253972.4   60972.7
526428  5253972.4   60599.3
526432.1    5253972.4   60154.9
526436.2    5253972.4   60802.8
526440.3    5253972.4   60958.2
526444.4    5253972.4   60530.1
526448.6    5253972.4   60229.9
526452.7    5253972.4   60197.6
526456.8    5253972.4   60425.8
526460.9    5253972.4   60450.8
526465  5253972.4   59787.6
526469.1    5253972.4   59404.4
526473.2    5253972.4   60447.7
526477.3    5253972.4   61011.9
526481.4    5253972.4   61304
526485.6    5253972.4   61404
526489.7    5253972.4   61431.8
526493.8    5253972.4   61455.5
526497.9    5253972.4   61489.8
526502  5253972.4   61445.9
526506.1    5253972.4   61581.3
526510.2    5253972.4   61723.1
526514.3    5253972.4   61744.5
526518.4    5253972.4   61759.3
526522.6    5253972.4   61651.6
526526.7    5253972.4   61357.4
526530.8    5253972.4   61088.1
526534.9    5253972.4   61505.6
526539  5253972.4   61793.5
526543.1    5253972.4   61846.8
526547.2    5253972.4   61890.7
526551.3    5253972.4   61929
526555.4    5253972.4   61953.5
526559.6    5253972.4   62004
526563.7    5253972.4   62017.1
526567.8    5253972.4   62069.5
526571.9    5253972.4   62119.6
526576  5253972.4   62142.3
526580.1    5253972.4   62190.1
526584.2    5253972.4   62239.9
526588.3    5253972.4   62268.3
526592.4    5253972.4   62257.5
526596.6    5253972.4   62212.8
526600.7    5253972.4   62193.3
526604.8    5253972.4   62137
526608.9    5253972.4   62084.3
526613  5253972.4   62075.9
526617.1    5253972.4   62072.8
526621.2    5253972.4   62030.6
526625.3    5253972.4   62100.9
526629.4    5253972.4   62107.4
526633.6    5253972.4   62124.6
526637.7    5253972.4   62140.9
526641.8    5253972.4   62249.8
526645.9    5253972.4   62275.2
526650  5253972.4   62325
526243  5253976.5   62069.2
526247.1    5253976.5   62037.5
526251.2    5253976.5   61984.2
526255.3    5253976.5   62000.4
526259.4    5253976.5   62020.3
526263.6    5253976.5   62019.6
526267.7    5253976.5   62028.1
526271.8    5253976.5   62079.9
526275.9    5253976.5   62095.9
526280  5253976.5   62084.5
526284.1    5253976.5   62129.4
526288.2    5253976.5   62203.6
526292.3    5253976.5   62304.3
526296.4    5253976.5   62380.6
526300.6    5253976.5   62398
526304.7    5253976.5   62358.6
526308.8    5253976.5   62323.8
526312.9    5253976.5   62283
526317  5253976.5   62240.6
526321.1    5253976.5   62175.5
526325.2    5253976.5   62113.9
526329.3    5253976.5   62021.2
526333.4    5253976.5   61958.1
526337.6    5253976.5   61902.3
526341.7    5253976.5   61846.7
526345.8    5253976.5   61647.2
526349.9    5253976.5   61442.7
526354  5253976.5   61346.2
526358.1    5253976.5   61387.1
526362.2    5253976.5   61324.2
526366.3    5253976.5   61168.7
526370.4    5253976.5   61043.5
526374.6    5253976.5   60854.9
526378.7    5253976.5   60797.1
526382.8    5253976.5   60889.2
526386.9    5253976.5   60915.6
526391  5253976.5   60822.2
526395.1    5253976.5   60760.4
526399.2    5253976.5   60700.1
526403.3    5253976.5   60540.3
526407.4    5253976.5   60525.5
526411.6    5253976.5   60693.8
526415.7    5253976.5   60905.6
526419.8    5253976.5   61065.2
526423.9    5253976.5   60992.9
526428  5253976.5   60873.2
526432.1    5253976.5   60135.2
526436.2    5253976.5   60421.8
526440.3    5253976.5   60699.9
526444.4    5253976.5   60422.8
526448.6    5253976.5   60075.5
526452.7    5253976.5   59948.4
526456.8    5253976.5   60170.3
526460.9    5253976.5   60534
526465  5253976.5   59849.7
526469.1    5253976.5   59221.9
526473.2    5253976.5   59961.2
526477.3    5253976.5   60589
526481.4    5253976.5   60958.8
526485.6    5253976.5   61166
526489.7    5253976.5   61296.1
526493.8    5253976.5   61335.3
526497.9    5253976.5   61448
526502  5253976.5   61423.1
526506.1    5253976.5   61574.7
526510.2    5253976.5   61769.1
526514.3    5253976.5   61774.9
526518.4    5253976.5   61847.8
526522.6    5253976.5   61888.6
526526.7    5253976.5   61915.7
526530.8    5253976.5   61965.2
526534.9    5253976.5   61939
526539  5253976.5   61954.5
526543.1    5253976.5   61935.2
526547.2    5253976.5   61942.9
526551.3    5253976.5   61951.1
526555.4    5253976.5   61998.7
526559.6    5253976.5   61981.4
526563.7    5253976.5   61991.2
526567.8    5253976.5   62052.1
526571.9    5253976.5   62141.2
526576  5253976.5   62167.5
526580.1    5253976.5   62175.5
526584.2    5253976.5   62277.2
526588.3    5253976.5   62363.1
526592.4    5253976.5   62262.3
526596.6    5253976.5   62178.3
526600.7    5253976.5   62151.2
526604.8    5253976.5   62143.3
526608.9    5253976.5   62092.3
526613  5253976.5   62073.4
526617.1    5253976.5   62072.3
526621.2    5253976.5   62030.2
526625.3    5253976.5   62096.5
526629.4    5253976.5   62110.7
526633.6    5253976.5   62115.6
526637.7    5253976.5   62139
526641.8    5253976.5   62251.8
526645.9    5253976.5   62277.1
526650  5253976.5   62337.3
526243  5253980.6   62066.3
526247.1    5253980.6   62048
526251.2    5253980.6   62002.1
526255.3    5253980.6   62005.9
526259.4    5253980.6   62016.9
526263.6    5253980.6   62024
526267.7    5253980.6   62054.9
526271.8    5253980.6   62109.2
526275.9    5253980.6   62090.7
526280  5253980.6   62121.7
526284.1    5253980.6   62169.8
526288.2    5253980.6   62245.1
526292.3    5253980.6   62311.2
526296.4    5253980.6   62336.4
526300.6    5253980.6   62305.7
526304.7    5253980.6   62294.3
526308.8    5253980.6   62252.1
526312.9    5253980.6   62203
526317  5253980.6   62172.3
526321.1    5253980.6   62097.8
526325.2    5253980.6   62031.2
526329.3    5253980.6   61944.4
526333.4    5253980.6   61889.2
526337.6    5253980.6   61820.7
526341.7    5253980.6   61742.6
526345.8    5253980.6   61514
526349.9    5253980.6   61344.2
526354  5253980.6   61245.2
526358.1    5253980.6   61238.2
526362.2    5253980.6   61181.5
526366.3    5253980.6   61034
526370.4    5253980.6   60946.3
526374.6    5253980.6   60761.3
526378.7    5253980.6   60579.3
526382.8    5253980.6   60575.5
526386.9    5253980.6   60797.7
526391  5253980.6   60773.6
526395.1    5253980.6   60771.5
526399.2    5253980.6   60727.6
526403.3    5253980.6   60545.5
526407.4    5253980.6   60405.8
526411.6    5253980.6   60482.8
526415.7    5253980.6   60903.6
526419.8    5253980.6   61087.6
526423.9    5253980.6   61206.6
526428  5253980.6   61175.3
526432.1    5253980.6   60749.5
526436.2    5253980.6   60558.7
526440.3    5253980.6   60418
526444.4    5253980.6   60293.5
526448.6    5253980.6   60012
526452.7    5253980.6   59445.5
526456.8    5253980.6   59617.3
526460.9    5253980.6   60258.1
526465  5253980.6   60222.1
526469.1    5253980.6   59939.5
526473.2    5253980.6   60081.4
526477.3    5253980.6   60348.9
526481.4    5253980.6   60695.2
526485.6    5253980.6   60930.1
526489.7    5253980.6   61133.6
526493.8    5253980.6   61264.2
526497.9    5253980.6   61349.5
526502  5253980.6   61355.8
526506.1    5253980.6   61398.3
526510.2    5253980.6   61698.9
526514.3    5253980.6   61786.7
526518.4    5253980.6   61866.2
526522.6    5253980.6   62075.3
526526.7    5253980.6   62405.3
526530.8    5253980.6   62759.8
526534.9    5253980.6   62307.7
526539  5253980.6   62091.4
526543.1    5253980.6   61996.8
526547.2    5253980.6   61953.2
526551.3    5253980.6   61935.6
526555.4    5253980.6   61932.6
526559.6    5253980.6   61922.5
526563.7    5253980.6   61940.6
526567.8    5253980.6   61991.2
526571.9    5253980.6   62040.7
526576  5253980.6   62075.9
526580.1    5253980.6   62104.3
526584.2    5253980.6   62151.5
526588.3    5253980.6   62193.7
526592.4    5253980.6   62166.6
526596.6    5253980.6   62121.4
526600.7    5253980.6   62098.5
526604.8    5253980.6   62100
526608.9    5253980.6   62070.9
526613  5253980.6   62061.9
526617.1    5253980.6   62064.2
526621.2    5253980.6   62018.3
526625.3    5253980.6   62088.8
526629.4    5253980.6   62102.2
526633.6    5253980.6   62107.7
526637.7    5253980.6   62133.7
526641.8    5253980.6   62251.3
526645.9    5253980.6   62280.6
526650  5253980.6   62348
526243  5253984.7   62070.5
526247.1    5253984.7   62032.9
526251.2    5253984.7   61995.8
526255.3    5253984.7   62013.9
526259.4    5253984.7   62021.1
526263.6    5253984.7   62031.5
526267.7    5253984.7   62062.8
526271.8    5253984.7   62111.6
526275.9    5253984.7   62114.9
526280  5253984.7   62139
526284.1    5253984.7   62200.9
526288.2    5253984.7   62248.8
526292.3    5253984.7   62278.6
526296.4    5253984.7   62268.5
526300.6    5253984.7   62259.9
526304.7    5253984.7   62234.8
526308.8    5253984.7   62189.8
526312.9    5253984.7   62159.2
526317  5253984.7   62085
526321.1    5253984.7   62005
526325.2    5253984.7   61934.3
526329.3    5253984.7   61855.4
526333.4    5253984.7   61811.4
526337.6    5253984.7   61785.8
526341.7    5253984.7   61567.1
526345.8    5253984.7   61412.7
526349.9    5253984.7   61300.2
526354  5253984.7   61168
526358.1    5253984.7   61129.6
526362.2    5253984.7   61029.5
526366.3    5253984.7   60792.3
526370.4    5253984.7   60739
526374.6    5253984.7   60601.2
526378.7    5253984.7   60352.3
526382.8    5253984.7   60250.4
526386.9    5253984.7   60371.7
526391  5253984.7   60576.7
526395.1    5253984.7   60709.4
526399.2    5253984.7   60647.8
526403.3    5253984.7   60407.7
526407.4    5253984.7   60270.3
526411.6    5253984.7   60235.8
526415.7    5253984.7   60576.9
526419.8    5253984.7   60782.5
526423.9    5253984.7   61177.2
526428  5253984.7   61308.1
526432.1    5253984.7   61268.4
526436.2    5253984.7   60831.1
526440.3    5253984.7   60244.9
526444.4    5253984.7   60060.9
526448.6    5253984.7   60139.4
526452.7    5253984.7   59810.3
526456.8    5253984.7   59954
526460.9    5253984.7   60277.9
526465  5253984.7   60327.2
526469.1    5253984.7   60454.4
526473.2    5253984.7   60387.6
526477.3    5253984.7   60202.1
526481.4    5253984.7   60292.2
526485.6    5253984.7   60657.1
526489.7    5253984.7   60909
526493.8    5253984.7   61070.8
526497.9    5253984.7   61128.9
526502  5253984.7   61233.6
526506.1    5253984.7   61286.2
526510.2    5253984.7   61543.5
526514.3    5253984.7   61691.4
526518.4    5253984.7   61822.6
526522.6    5253984.7   62016.1
526526.7    5253984.7   62274.3
526530.8    5253984.7   62299.4
526534.9    5253984.7   62263.7
526539  5253984.7   62161.4
526543.1    5253984.7   62070.3
526547.2    5253984.7   61992.3
526551.3    5253984.7   61919.4
526555.4    5253984.7   61842.4
526559.6    5253984.7   61810.8
526563.7    5253984.7   61862.3
526567.8    5253984.7   61926.4
526571.9    5253984.7   61919
526576  5253984.7   61948.4
526580.1    5253984.7   61989.3
526584.2    5253984.7   62017
526588.3    5253984.7   62065.8
526592.4    5253984.7   62058.4
526596.6    5253984.7   62053.2
526600.7    5253984.7   62041.8
526604.8    5253984.7   62066.9
526608.9    5253984.7   62072.8
526613  5253984.7   62072.4
526617.1    5253984.7   62055.3

抱歉,条目未对齐,这是从 MS Excel 中复制出来的...

数据排列为一系列线,这些线组合起来构成一个坐标列表,该列表来自由最上面和下面的点“x”和“y”值界定的区域上的网格。

导致我的脚本挂起的问题是子采样数据集(我试图将其网格化以便将其计数图像与主数据集进行比较)的线起点和终点未对齐。对于使用奇数子间隔创建的所有子采样数据集都是如此。

我通过在“for”循环中使用额外的检查来对数据集进行二次采样来解决这个问题。

这是固定的“子样本”代码。

 - Note: The plotting code works seamlessly.

    def sub_sample():
        print ""
        print " - This program will sub-sample a dataset for every <n> datapoint."
        print " - <n> should realistically should be between 1 and 10."
        print " - If <n> > 10, interpretation confidence is reduced significantly."
        print ""
        n = raw_input(" - What value should <n> take?: ")

        if int(n) > 0 and int(n) < 2001:
            print ""
            print " - You have chosen to subsample the data every "+str(n)+" datapoints."

            perc = (float(1)/float(n)*int(100))
            print " - This corresponds to "+str(perc)+" percent of the data."

            indataarray = numpy.loadtxt("out.csv", skiprows=1, delimiter=',')

            out_name = "every_"+str(n)+".csv"     

            t = indataarray.shape
            totalrows = t[0]
            totalcolumns = t[1]
            holding_array = numpy.zeros( [totalrows, totalcolumns] )

            for i in range(totalrows):

                if ((i % 100) % int(n) == 0):
                    for j in range(totalcolumns):
                        holding_array[i,j] = indataarray[i,j] 

            no_zeros = (holding_array == 0).sum(1)
            new_holding = holding_array[no_zeros == 0, :]
            numpy.savetxt(out_name, new_holding, delimiter=',', fmt='%f')

            hdr_c1 = 'Easting,'
            hdr_c2 = 'Northing,'
            hdr_c3 = 'TMI_nT'

            f = open(out_name)
            text = f.read()
            f.close()

            f = open(out_name, 'w')
            f.write(hdr_c1+hdr_c2+hdr_c3+'\n')
            f.write(text)
            f.close
            print " - The file "+out_name+" has been created."

        else:
            print ""
            print " - You have entered an unrealistic value for <n>."
            print " - Please try again."
            sub_sample()

它失败了,因为你试图插值very陌生的地区。

查看您的输入坐标,您的数据都在一条线上,但您正在尝试以二维方式进行插值。你的yi坐标都是一样的!

enter image description here

如果您想要一维插值,那么只需使用众多一维插值例程之一...(numpy.interp如果你只想线性插值或scipy.interp1d如果您需要某种样条线。还有其他几种选择......)。

完整的数据集是什么样的?

griddata默认使用 delaunay 三角剖分。每当您最终在输入点之间制作非常薄的、面积接近于零的三角形时,该算法就会出现问题。

If you really想要在面积为 2D 的区域上进行插值zero(请参阅此处的问题!!)尝试另一种(最好是一维)插值算法。如果您需要帮助,请告诉我。

如果你真的想要一个“伪二维”插值,scipy.interpolate.Rbf使用线性距离函数是一种选择。请注意,(2D)结果可能不是您所期望的,因为您在 y 方向上绝对没有变化......

或者,如果您希望 y 方向上的所有内容都相同,则可以仅在 y 方向上平铺一维插值结果。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用“matplotlib.mlab.griddata”时程序挂起 的相关文章

  • InterfaceError:连接已关闭(使用 django + celery + Scrapy)

    当我在 Celery 任务中使用 Scrapy 解析函数 有时可能需要 10 分钟 时 我得到了这个信息 我用 姜戈 1 6 5 django celery 3 1 16 芹菜 3 1 16 psycopg2 2 5 5 我也使用了psyc
  • 如何使用固定的 pandas 数据框进行动态 matplotlib 绘图?

    我有一个名为的数据框benchmark returns and strategy returns 两者具有相同的时间跨度 我想找到一种方法以漂亮的动画风格绘制数据点 以便它显示逐渐加载的所有点 我知道有一个matplotlib animat
  • 更改自动插入 tkinter 小部件的文本颜色

    我有一个文本框小部件 其中插入了三条消息 一条是开始消息 一条是结束消息 一条是在 单位 被摧毁时发出警报的消息 我希望开始和结束消息是黑色的 但被毁坏的消息 参见我在代码中评论的位置 插入小部件时颜色为红色 我不太确定如何去做这件事 我看
  • Spark的distinct()函数是否仅对每个分区中的不同元组进行洗牌

    据我了解 distinct 哈希分区 RDD 来识别唯一键 但它是否针对仅移动每个分区的不同元组进行了优化 想象一个具有以下分区的 RDD 1 2 2 1 4 2 2 1 3 3 5 4 5 5 5 在此 RDD 上的不同键上 所有重复键
  • 为 pandas 数据透视表中的每个值列定义 aggfunc

    试图生成具有多个 值 列的数据透视表 我知道我可以使用 aggfunc 按照我想要的方式聚合值 但是如果我不想对两列求和或求平均值 而是想要一列的总和 同时求另一列的平均值 该怎么办 那么使用 pandas 可以做到这一点吗 df pd D
  • 从 scikit-learn 导入 make_blobs [重复]

    这个问题在这里已经有答案了 我收到下一个警告 D Programming Python ML venv lib site packages sklearn utils deprecation py 77 DeprecationWarning
  • IRichBolt 在storm-1.0.0 和 pyleus-0.3.0 上运行拓扑时出错

    我正在运行风暴拓扑 pyleus verbose local xyz topology jar using storm 1 0 0 pyleus 0 3 0 centos 6 6并得到错误 线程 main java lang NoClass
  • NameError:名称“urllib”未定义”

    CODE import networkx as net from urllib request import urlopen def read lj friends g name fetch the friend list from Liv
  • python pandas 中的双端队列

    我正在使用Python的deque 实现一个简单的循环缓冲区 from collections import deque import numpy as np test sequence np array range 100 2 resha
  • 在pyyaml中表示具有相同基类的不同类的实例

    我有一些单元测试集 希望将每个测试运行的结果存储为 YAML 文件以供进一步分析 YAML 格式的转储数据在几个方面满足我的需求 但测试属于不同的套装 结果有不同的父类 这是我所拥有的示例 gt gt gt rz shorthand for
  • Abaqus 将曲面转化为集合

    我一直试图在模型中找到两个表面的中心 参见照片 但未能成功 它们是元素表面 面 查询中没有选项可以查找元素表面的中心 只能查找元素集的中心 找到节点集的中心也很好 但是我的节点集没有出现在工具 gt 查询 gt 质量属性选项中 而且我找不到
  • 当玩家触摸屏幕一侧时,如何让 pygame 发出警告?

    我使用 pygame 创建了一个游戏 当玩家触摸屏幕一侧时 我想让 pygame 给出类似 你不能触摸屏幕两侧 的错误 我尝试在互联网上搜索 但没有找到任何好的结果 我想过在屏幕外添加一个方块 当玩家触摸该方块时 它会发出警告 但这花了很长
  • 如何将 numpy.matrix 提高到非整数幂?

    The 运算符为numpy matrix不支持非整数幂 gt gt gt m matrix 1 0 0 5 0 5 gt gt gt m 2 5 TypeError exponent must be an integer 我想要的是 oct
  • Numpy 优化

    我有一个根据条件分配值的函数 我的数据集大小通常在 30 50k 范围内 我不确定这是否是使用 numpy 的正确方法 但是当数字超过 5k 时 它会变得非常慢 有没有更好的方法让它更快 import numpy as np N 5000
  • 如何改变Python中特定打印字母的颜色?

    我正在尝试做一个简短的测验 并且想将错误答案显示为红色 欢迎来到我的测验 您想开始吗 是的 祝你好运 法国的首都是哪里 法国 随机答案不正确的答案 我正在尝试将其显示为红色 我的代码是 print Welcome to my Quiz be
  • Nuitka 未使用 nuitka --recurse-all hello.py [错误] 编译 exe

    我正在尝试通过 nuitka 创建一个简单的 exe 这样我就可以在我的笔记本电脑上运行它 而无需安装 Python 我在 Windows 10 上并使用 Anaconda Python 3 我输入 nuitka recurse all h
  • Python:计算字典的重复值

    我有一本字典如下 dictA unit1 test1 alpha unit1 test2 beta unit2 test1 alpha unit2 test2 gamma unit3 test1 delta unit3 test2 gamm
  • 在python中,如何仅搜索所选子字符串之前的一个单词

    给定文本文件中的长行列表 我只想返回紧邻其前面的子字符串 例如单词狗 描述狗的单词 例如 假设有这些行包含狗 hotdog big dog is dogged dog spy with my dog brown dogs 在这种情况下 期望
  • 在 Python 类中动态定义实例字段

    我是 Python 新手 主要从事 Java 编程 我目前正在思考Python中的类是如何实例化的 我明白那个 init 就像Java中的构造函数 然而 有时 python 类没有 init 方法 在这种情况下我假设有一个默认构造函数 就像
  • 改变字典的哈希函数

    按照此question https stackoverflow com questions 37100390 towards understanding dictionaries 我们知道两个不同的字典 dict 1 and dict 2例

随机推荐