view +anim/setup_surf_plot.m @ 577:e45c9b56d50d feature/grids

Add an Empty grid class The need turned up for the flexural code when we may or may not have a grid for the open water and want to plot that solution. In case there is no open water we need an empty grid to plot the empty gridfunction against to avoid errors.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 07 Sep 2017 09:16:12 +0200
parents f87003695677
children
line wrap: on
line source

function [update_data,figure_handle] = setup_2d_plot(x,y,z_lim,zfun)
    default_arg('zfun',@(z)z);

    Z = zeros(length(y),length(x));
    figure_handle = figure;
    plot_handle = surf(x,y,Z);
    plot_handle.LineStyle = 'none';
    axis_handle = gca;

    xlabel('x')
    ylabel('y')
    xlim([x(1) x(end)]);
    ylim([y(1) y(end)]);
    zlim(z_lim);
    caxis(z_lim);
    % axis vis3d
    % colormap(parula(256))
    % colorbar

    function update(t,z)
        Z = zfun(z);
        % Z = reshape(zfun(z),length(x),length(y));
        if ishandle(plot_handle) && ishandle(axis_handle)
            set(plot_handle,'ZData',Z)
            title(axis_handle,sprintf('T=%.3f',t));
        end
    end
    update_data = @update;
end