To fix this you have to use caxis
to set the limits for the contourf
plot:
clc; clear all; close all;
x = linspace(-2*pi,2*pi);
y = linspace(0,4*pi);
[X1,Y1] = meshgrid(x,y);
Z1 = sin(X1)+cos(Y1);
[X2,Y2] = meshgrid(x,y);
Z2 = 1000*(sin(1.2*X2)+2*cos(Y2));
figure;
contourf(X1,Y1,Z1);
shading flat;
caxis([min(min(Z1)) max(max(Z1))]);
hold on;
contour(X2,Y2,Z2,'k');
You can replace min(min(Z1))
and max(max(Z1))
with the upper and lower limits that you want. This results in this plot: