How to visualize and understand Gabor filter using MATLAB
The following is my implementation, of the above problem :

In my_gabor_filter.m, I have the following code :

function psi = my_gabor_filter(x,y,mu,nu,sigma) 
    phi = pi*mu/8;
    f = sqrt(2);
    k_max = pi/2;
    k_nu = k_max/(f^nu);

    % This is the wave vector
    k_vec = [k_nu*cos(phi),k_nu*sin(phi)]';
    z_vec = [x,y]';

    k_vec_norm = norm(k_vec);
    z_vec_norm = norm(z_vec);

    exp1 = (k_vec_norm/(sigma^2));
    exp2 = (exp(-((k_vec_norm^2)*(z_vec_norm^2)/(2*sigma^2))));
    exp3 = (exp(complex(0,k_vec'*z_vec))-exp(-(sigma^2/2)));

    psi = exp1*exp2*exp3;
end


and, in plot_gabor_filter.m I did the following :

function plot_gabor_filter()
    mu = 0;
    nu = 0;
    sigma = 1;

    [X,Y] = meshgrid(-2:0.1:2,-2:0.1:2);

    Z = zeros(41,41);

    for i = 1:1:41
        for j = 1:1:41
            Z(i,j) = imag(my_gabor_filter(X(i,j),Y(i,j),mu,nu,sigma));
        end
    end

    surf(X,Y,Z,'EdgeColor','black')

    xlabel('x axis');
    ylabel('y axis');
    zlabel('g(x,y)');
end


and when I run plot_gabor_filter, I get the following output, which helped me in visualizing the gabor function :