MATLAB Answers

contourf plot gives white bands

16 views (last 30 days)
Jelo Zariba
Jelo Zariba on 18 Jan 2021
Commented: Star Strider on 19 Jan 2021
I am learning to use Matlab / Octave because I will be tutoring a student in a Diffential Equation course this semester in 2nd year Calculus. But my retired passion is violin making and I want to explore Matlabs graphing capabilties in connection with making a graduation map of the thicknesses of a violin back. I have a data file of maybe a couple of hundred points x y z format. The x y is not only the 2D outline of the violin plate but also the locations of where the thickness measurements were taken. z is the thickness of a violin plate in mm. I have followed an example of how to read the data into a matrix and how to reshape the data for the contour plot. Also I am using a color scheme that represents what you would see if you hold the plate in front of a strong light. The problem is the output has white bands separating the contour map ??? What is causing the white bands? The code works so there must be a error in the data file.
hold on;
plot (x,y,"o");


Sign in to comment.

Answers (1)

Star Strider
Star Strider on 18 Jan 2021
Without your data, it is not possible to determine with any certainty what the problem is.
Two observations:
The colon operator uses a default step of 1 between the min and max values for each vector, and if the ‘ends’ of the vector are not exactly 1 more than the previous value, the vector will not include the max values and the vector will be shortened, so will not include them. A more robust option might be to use the linspace function to define vectors with increased resolution that by definition will include the end values. (A recent example is Plot contour with 3 variables, although you will want more than the 20 elements that are likely appropriate in that example, so consider at least 50.)
consider using either more levels, or let contourf decide on the number of levels, at least initially. The white areas appear to be where the data are missing, so that option is worth exploring.


Jelo Zariba
Jelo Zariba on 19 Jan 2021
Thanks for your help. I will look into that. The data file looks like this for the internal points
1168 355 3.68 0
1161 458 2.77 0
1101 582 2.54 0
1104 520 2.54 0
and this for the outline
113 520 4 1
124 541 4 1
137 563 4 1
155 580 4 1
I am ignoring the 4th number which has to do with layers
Star Strider
Star Strider on 19 Jan 2021
My pleasure!
I agree with your approach. The problem appears to be with the way you create the vectors. I would do:
xv = linspace(min(x), max(x), 250);
yv = linspace(min(y), max(y), 250);
[X,Y] = meshgrid(xv, yv);
varying the vector lengths depending on the detail you want, since I believe the gap is created by the inherent properties of the colon operator. If I am correct, the approach I outlined here should eliminate the gaps.
Also consider using ndgrid if meshgrid causes problems, since some functions — and I cannot now remember which ones — require ndgrid matrices, others meshgrid matrices, and still others apparently are not at all restrictive.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!