
function jSurface = plotGMM2d(dimensions, mixChecked, dim1, dim2, weights, means, variances, allvariances, resolution, color, zero, ratio)

    M = length(means);    
    minx1 = [];
    maxx1 = [];
    minx2 = [];
    maxx2 = [];
    
    for m = 1:M
        if(mixChecked(m) == 1)
            deltaX1 = sqrt(-2.0*variances(1,1,m)*(log(zero)+0.5*log((2*pi)^dimensions*prod(allvariances(m,:))))); 
            deltaX2 = sqrt(-2.0*variances(2,2,m)*(log(zero)+0.5*log((2*pi)^dimensions*prod(allvariances(m,:)))));        
            minx1(m) = means(1,1,m)-deltaX1;
            maxx1(m) = means(1,1,m)+deltaX1;
            minx2(m) = means(2,1,m)-deltaX2;
            maxx2(m) = means(2,1,m)+deltaX2;
        end
    end

    minX1 = min(minx1);
    minX2 = min(minx2);
    maxX1 = max(maxx1);
    maxX2 = max(maxx2);
    
    t1 = (abs(minX1)+abs(maxX1)) / resolution;
    t2 = (abs(minX2)+abs(maxX2)) / resolution;
    x1 = minX1 : t1 : maxX1;
    x2 = minX2 : t2 : maxX2;
    
    z = gmm2d(x1, x2, dimensions, mixChecked, weights, means, variances, allvariances);
    if(ratio)
        z = log(z);
    end
    jSurface  = surf(z,'XData', x1, 'YData', x2, 'FaceColor', color, 'EdgeColor', color);
    alpha(0.6); % set transparency of surface 
    view(3); grid on; box on; % enclose the axis in a box
    
    xlb = strcat('X dim', num2str(dim1));
    ylb = strcat('Y dim', num2str(dim2));
    xlabel(xlb);
    ylabel(ylb);
    zlabel('Z');
    
end
