在matbplotlib pcolormesh上缺少值

时间:2017-06-20 16:10:12

标签: python matplotlib

我在colormesh上缺少矩形的问题 - 似乎只显示了最低的值。 代码:

import numpy as np
import matplotlib.pyplot as plt
# X_dat, Y_dat, Z_dat here are vectors, X_dat has a repeating values (eg. [0,0,0,0.5,0.5,0.5])
# where Y_dat not necessarily (but it can have)
X_dat = data[:,0]
Y_dat = data[:,1]
Z_dat = data[:,3]

# here I try to put nans in the places where there is no data
X, Y = np.meshgrid(X_dat,Y_dat, sparse = False)
Z = np.zeros(np.shape(X))
for i in range(0,len(X)):
    for j in range(0,len(Y)):
        temp = np.where((X_dat == X[1,i])*(Y_dat == Y[j,1]) == True)
        if np.any(temp):
            tp = temp[0][0]
            Z[j,i] = Z_dat[tp]
        else:
            Z[j,i] = np.nan

plo = plt.pcolormesh(X,Y,Z.T,vmin=np.nanmin(Z_dat), vmax=np.nanmax(Z_dat))
plo.cmap.set_under('white')
plt.colorbar()
plt.show()

但输出只是数据中间的一些矩形,只显示最低值。我仔细检查过Z矩阵中有一些高值(大约2600)。我发现一些信息表明Z需要是一行,一列小于X和Y(是吗?),但它仍然不起作用。

enter image description here

我有什么明显的遗失吗?

示例性数据:(我只使用第1列,第2列和第4列)

1.950000    -0.062821   6.780000    14.890000   1925.000000
1.950000    -0.012821   7.080000    15.980000   1688.140000
1.950000    0.037179    7.520000    16.640000   1973.680000
1.950000    0.087179    8.040000    18.680000   1833.640000
1.950000    0.137179    9.070000    21.710000   2029.170000
1.950000    0.187179    10.410000   26.030000   1518.330000
1.950000    0.237179    12.910000   34.810000   1803.350000
1.950000    0.287179    16.450000   49.560000   2319.620000
1.950000    0.337179    21.980000   74.370000   2605.610000
1.950000    0.387179    29.520000   109.410000  3287.010000
1.950000    0.437179    31.650000   112.650000  2791.700000
2.000000    -0.450000   4.280000    10.040000   2533.620000
2.000000    -0.400000   4.150000    9.970000    3145.760000
2.000000    -0.350000   3.890000    9.220000    2952.020000
2.000000    -0.300000   4.090000    9.470000    2541.860000
2.000000    -0.250000   4.060000    9.740000    2914.300000
2.000000    -0.200000   4.130000    9.740000    3291.510000
2.000000    -0.150000   4.210000    9.840000    2761.370000
2.000000    -0.100000   4.240000    10.120000   3193.010000
2.000000    -0.050000   4.420000    10.550000   2953.860000
2.000000    -0.000000   4.740000    11.060000   3162.100000
2.000000    0.050000    5.240000    12.260000   3010.260000
2.000000    0.100000    6.250000    15.450000   2941.040000
2.000000    0.150000    7.610000    19.840000   2779.810000
2.000000    0.200000    9.940000    29.210000   3754.370000
2.000000    0.250000    13.870000   45.480000   3262.260000
2.000000    0.300000    25.720000   116.770000  3985.720000
2.000000    0.350000    51.420000   292.570000  4644.860000
2.000000    0.400000    141.350000  1014.520000 4899.480000
2.000000    0.450000    369.130000  2640.330000 4999.000000

0 个答案:

没有答案