I have a 2 dimensional Numpy NDarray filled with floats between 0 and about 8. This 2 dimensional arrays size is (1000, 1600)
and there are about 1400 values, (the points in the point cloud), the remaining values are None
, so matplotlib does not plot these values. You can see the plotted table in the image below. What I'd like to have is, the None-values interpolated with the values next to it to have a gradientlike heatmap. This pointcloud represents the shape of a roof and I want to process this data to an image I can give into a neural network to detect the type of roof.
The code I used for this plot is pretty short,
import matplotlib.pyplot as plt
plt.clf()
#plotGrid is the numpy.ndarray with shape (1000, 1600) and dtype float
plt.imshow(plotGrid, cmap='gray', interpolation='nearest')
plt.colorbar()
plt.show()
tricontouf
You might use a tricontour plot of the valid values. To this end, you first need to filter out all
nan
values (you should indeed make the invalid valuesnp.nan
instead ofNone
). Those values, together with their coordinates can be put intoplt.tricontour()
to obtain a contour plot without the need of manual interpolation.tripcolor
Using
tripcolor
is another option then:interpolate and
contourf
You can also interpolate the data on a grid first, using
matplotlib.mlab.griddata
, and then either use a normalcontourf
plot,interpolate and
imshow
Or in the same manner use an
imshow
plot,I think
scipy.interpolate.interp2d
does what you need: