recipes : Plotting : 2D Data : Interpolating a pcolor plot creates odd artefacts


Choosing the shading interp option with the pcolor command is creating weird shapes that don't resemble the underlying data.


The interp option isn't "clever", it just interpolates between the data that you give it. It will give bad results unless you provide it with sensible input. For example, let's see what happens if we try to interpolate a smooth 2-D function that has been sampled at low resolution.


shading flat
title('flat'), axis off

shading interp %Ask pcolor to interpolate between cells
title('interp'), axis off

The left plot shows what the raw data look like. The right plot shows the effect of shading interp. It looks rather ugly and jagged. To fix this we need to interpolate the data over a finer grid before smoothing.

shading interp
axis off

This obviously looks far better than our first attempt at making an interpolated plot. This works as well as it does because the original data weren't noisy and were obtained from a smooth distribution. In practice this won't always be the case, so you will need other tricks up your sleeve too. Here's what to try if the data are noisy:

NOISE=MAT+rand(size(MAT))*2; %Add noise

subplot(2,2,1) %Show the raw data
pcolor(MAT), shading interp, axis off
title('A. raw data')

subplot(2,2,2) %Show the noisy data
pcolor(NOISE), shading interp, axis off
title('B. noisy data')

subplot(2,2,3) %The effect of interpolating noisy data
pcolor(interp2(NOISE,5,'linear')), shading interp, axis off
title('C. interpolated data')

subplot(2,2,4) %Smooth the noisy data then interpolate
NOISE=conv2(NOISE,ones(3),'same'); %average out the noise
pcolor(NOISE), shading interp, axis off
title('D. smoothed then interpolated')

Applying shading interp to noisy data makes for a rather ugly plot (B), because the noise creates odd artefacts. Interpolating the data before plotting doesn't help (C) because it's not getting rid of the noise. In plot D, therefore, we first average out the noise and then plot. No extra interpolation is needed. The plot in D looks reasonably like the original data in A.


Blindly using the shading interp option can create ugly artefacts which aren't related to the underlying data. Fixing these requires some understanding of what the underlying data are. In first case, where there is no noise, it is best to simply interpolate and smooth the data over a finer grid. In the second case, we must try to get rid of noise by averaging. Every data set is different, but the goal is always to produce the representation that most resembles what you think the underlying data look like. Usually jagged edges, which shading interp is likely to produce if mis-used, is not the correct answer.


Want to continue the discussion?
Enter your comments, suggestions, or thoughts below

comments powered by Disqus