Mercurial > repos > public > sbplib
comparison +anim/setup_2d_plot.m @ 0:48b6fb693025
Initial commit.
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Thu, 17 Sep 2015 10:12:50 +0200 |
| parents | |
| children | f87003695677 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:48b6fb693025 |
|---|---|
| 1 function [update_data,figure_handle] = setup_2d_plot(x,y,clim,zfun) | |
| 2 default_arg('zfun',@(z)z); | |
| 3 | |
| 4 Z = zeros(length(x),length(y)); | |
| 5 figure_handle = figure; | |
| 6 plot_handle = imagesc(x,y,Z); | |
| 7 axis_handle = gca; | |
| 8 | |
| 9 xlabel('x') | |
| 10 ylabel('y') | |
| 11 xlim([x(1) x(end)]); | |
| 12 ylim([y(1) y(end)]); | |
| 13 caxis(clim); | |
| 14 % axis vis3d | |
| 15 colormap(parula(256)) | |
| 16 colorbar | |
| 17 | |
| 18 function update(t,z) | |
| 19 Z = zfun(z); | |
| 20 % Z = reshape(zfun(z),length(x),length(y)); | |
| 21 if ishandle(plot_handle) && ishandle(axis_handle) | |
| 22 set(plot_handle,'CData',Z) | |
| 23 title(axis_handle,sprintf('T=%.3f',t)); | |
| 24 drawnow | |
| 25 end | |
| 26 end | |
| 27 update_data = @update; | |
| 28 end | |
| 29 | |
| 30 | |
| 31 % TODO | |
| 32 % This function is for squre grid. | |
| 33 % This function is for 2d image. | |
| 34 % Make one for 3d surface | |
| 35 % Make one for curvilinear grids using pcolor | |
| 36 | |
| 37 | |
| 38 function [update_data,figure_handle,plot_handles] = setup_1d_plot(x,y_lim,yfun) | |
| 39 | |
| 40 figure_handle = figure; | |
| 41 plot_handles(1) = plot(x,0*x); | |
| 42 hold on | |
| 43 for i = 2:length(yfun) | |
| 44 plot_handles(i) = plot(x,0*x); | |
| 45 end | |
| 46 hold off | |
| 47 | |
| 48 axis_handle = gca; | |
| 49 | |
| 50 xlabel('x') | |
| 51 ylabel('y') | |
| 52 xlim([x(1) x(end)]); | |
| 53 ylim(y_lim); | |
| 54 | |
| 55 function update(t,varargin) | |
| 56 if ishandle(figure_handle) && ishandle(axis_handle) | |
| 57 for i = 1:length(yfun) | |
| 58 set(plot_handles(i),'YData',yfun{i}(varargin{:})); | |
| 59 end | |
| 60 title(axis_handle,sprintf('T=%.3f',t)); | |
| 61 drawnow | |
| 62 end | |
| 63 end | |
| 64 update_data = @update; | |
| 65 end | |
| 66 | |
| 67 | |
| 68 |
