Mercurial > repos > public > sbplib
annotate +anim/setup_1d_plot.m @ 1037:2d7ba44340d0 feature/burgers1d
Pass scheme specific parameters as cell array. This will enabale constructDiffOps to be more general. In addition, allow for schemes returning function handles as diffOps, which is currently how non-linear schemes such as Burgers1d are implemented.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Fri, 18 Jan 2019 09:02:02 +0100 |
parents | df83c8095326 |
children |
rev | line source |
---|---|
56
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
1 % Creates a plot and provides a function to update the data in it. |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
2 % x - Vector of x-values to plot for. |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
3 % y_lim - 1x2 vector containing the y limits of the plot. |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
4 % yfun - Function or a cell array of functions of y data vectors |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
5 % that should be plotted. The output of each function |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
6 % will be plotted to the same axis. |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
7 % |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
8 % update_data(t,varargin) - Function to update plot data. All varargin will |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
9 % be passed to functions in yfun. |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
10 % plot_handles - Array of plot_handles. One for each yfun. |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
11 % axis_handle - Handle to the axis plotted to. |
145
df83c8095326
setup 1d plot: Removed setting of axislabels. Made time in title optional.
Jonatan Werpers <jonatan@werpers.com>
parents:
142
diff
changeset
|
12 function [update_data, plot_handles, axis_handle] = setup_1d_plot(x,yfun,show_title) |
0 | 13 default_arg('yfun',{@(y)y}); |
145
df83c8095326
setup 1d plot: Removed setting of axislabels. Made time in title optional.
Jonatan Werpers <jonatan@werpers.com>
parents:
142
diff
changeset
|
14 default_arg('show_title', true) |
0 | 15 |
48
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
16 if isa(yfun,'function_handle') |
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
17 yfun = {yfun}; |
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
18 end |
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
19 |
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
20 figure_handle = gcf; |
0 | 21 plot_handles(1) = plot(x,0*x); |
22 for i = 2:length(yfun) | |
66
dbc50fa58ca6
Made setup_1d_plot behave like matlab plot.
Jonatan Werpers <jonatan@werpers.com>
parents:
56
diff
changeset
|
23 plot_handles(i) = line(x,0*x); |
0 | 24 end |
25 | |
26 axis_handle = gca; | |
27 | |
28 xlim([x(1) x(end)]); | |
113
a4e1608ae980
1d plot: Made it possible to have automatix axes.
Jonatan Werpers <jonatan@werpers.com>
parents:
69
diff
changeset
|
29 |
0 | 30 function update(t,varargin) |
31 if ishandle(figure_handle) && ishandle(axis_handle) | |
32 for i = 1:length(yfun) | |
33 set(plot_handles(i),'YData',yfun{i}(varargin{:})); | |
34 end | |
145
df83c8095326
setup 1d plot: Removed setting of axislabels. Made time in title optional.
Jonatan Werpers <jonatan@werpers.com>
parents:
142
diff
changeset
|
35 |
df83c8095326
setup 1d plot: Removed setting of axislabels. Made time in title optional.
Jonatan Werpers <jonatan@werpers.com>
parents:
142
diff
changeset
|
36 if show_title |
df83c8095326
setup 1d plot: Removed setting of axislabels. Made time in title optional.
Jonatan Werpers <jonatan@werpers.com>
parents:
142
diff
changeset
|
37 title(axis_handle,sprintf('T=%.3f',t)); |
df83c8095326
setup 1d plot: Removed setting of axislabels. Made time in title optional.
Jonatan Werpers <jonatan@werpers.com>
parents:
142
diff
changeset
|
38 end |
0 | 39 end |
40 end | |
41 update_data = @update; | |
42 end |