ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
Tile.m
Go to the documentation of this file.
1%> \brief
2%> This is the abstract class for generating instances of objects
3%> that contain the specifications of various types of tile figures.<br>
4%>
5%> \details
6%> This is a generic class for generating figures
7%> containing multiple subplots (axes) of the same class.
8classdef Tile < pm.vis.Tiling
9
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
12 properties(Access = public)
13 %>
14 %> \param template : The scalar object of superclass [pm.vis.Subplot](@ref Subplot)
15 %> representing the template of the set of subplots to display.
16 %>
17 template = [];
18 %>
19 %> \param tileshape : The MATLAB vector ``[nrow, ncol]`` representing
20 %> the number of rows and columns in the tiled layout of subplots.
21 %> The default is the closest values of ``nrow`` and ``ncol`` whose
22 %> multiplication yields the maximum number of data columns in the
23 %> visualization.
24 %>
25 tileshape = [];
26 %>
27 %> \param tileindex : The MATLAB vector of size ``0`` or ``prod(tileshape)`` containing
28 %> the list of indices of the tiling to fill with subplots, starting
29 %>
30 %tileindex = [];
31 end
32
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34
35 methods(Access = public)
36
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38
39 %>
40 %> \note
41 %> This class is not meant to be used directly by the end users.
42 %> Instead, use the subclasses of this abstract class for visualizations.
43 %>
44 %> \param[in] template : The input scalar object of superclass [pm.vis.Subplot](@ref Subplot).
45 %> It serves as the template based upon which all subplots are constructed.
46 %>
47 %> \param[in] varargin : Any ``property, value`` pair of the parent object.<br>
48 %> If the property is a ``struct()``, then its value must be given as a cell array,
49 %> with consecutive elements representing the struct ``property-name, property-value`` pairs.
50 %> Note that all of these property-value pairs can be also directly set via the
51 %> parent object attributes, before calling the ``make()`` method.
52 %>
53 %> \note
54 %> The input ``varargin`` can also contain the components
55 %> of the ``template`` component of the parent object.
56 %>
57 %> \return
58 %> ``self`` : The output scalar object of class [pm.vis.Tile](@ref Tile).
59 %>
60 %> \interface{Tile}
61 %> \code{.m}
62 %>
63 %> tile = pm.vis.Tile(template);
64 %> tile = pm.vis.Tile(template, varargin);
65 %>
66 %> \endcode
67 %>
68 %> \note
69 %> See the list of class attributes below,
70 %> also those of the superclass [pm.vis.Tiling](@ref Tiling).
71 %>
72 %> \final{Tile}
73 %>
74 %> \author
75 %> \JoshuaOsborne, May 22 2024, 7:39 PM, University of Texas at Arlington<br>
76 function self = Tile(template, varargin)
77 [varobj, vartemp] = pm.matlab.hashmap.popKeyVal(["figure", "subplot", "template", "tiledlayout", "tileshape"], varargin);
78 self = self@pm.vis.Tiling(cell(0, 0), varobj{:});
79 self.template = template;
80 if ~isempty(vartemp)
81 self.template.hash2comp(vartemp);
82 end
83 end
84
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86
87 %> \brief
88 %> Reset the properties of the tile to the original default settings.
89 %> Use this method when you change many attributes of the tile and
90 %> you want to clean up and go back to the default settings.
91 %>
92 %> \param[in] varargin : Any ``property, value`` pair of the parent object.<br>
93 %> If the property is a ``struct()``, then its value must be given as a cell array,
94 %> with consecutive elements representing the struct ``property-name, property-value`` pairs.
95 %> Note that all of these property-value pairs can be also directly set via the
96 %> parent object attributes, before calling the ``make()`` method.
97 %>
98 %> \note
99 %> The input ``varargin`` can also contain the components
100 %> of the ``subplot`` component of the parent object.
101 %>
102 %> \interface{reset}
103 %> \code{.m}
104 %>
105 %> tile = pm.vis.Tile(template, varargin);
106 %> tile.reset(varargin)
107 %> tile.reset() % reset the tile to the default settings.
108 %>
109 %> \endcode
110 %>
111 %> \final{reset}
112 %>
113 %> \author
114 %> \JoshuaOsborne, May 22 2024, 7:42 PM, University of Texas at Arlington<br>
115 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
116 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
117 function reset(self, varargin)
118
119 self.tileshape = [];
120 [vartemp, varleft] = pm.matlab.hashmap.popKeyVal("template", varargin);
121 if ~isempty(vartemp)
122 self.hash2comp(vartemp);
123 %self.template.reset();
124 end
125 reset@pm.vis.Tiling(self, varleft{:});
126
127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 %%%% RULE 0: Any non-MATLAB-default setting must be preferably set in premake() method to override user null values.
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130
131 end
132
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134
135 %> \brief
136 %> Configure the tile settings and specifications,
137 %> make the tile, and return nothing.
138 %>
139 %> \details
140 %> In making the figure, this method we call the ``make()``
141 %> methods of each of the subplot objects stored in the
142 %> ``subplot`` component.
143 %>
144 %> \warning
145 %> This method has side-effects by manipulating
146 %> the existing attributes of the parent object.
147 %>
148 %> \param[in] varargin : Any ``property, value`` pair of the parent object.<br>
149 %> If the property is a ``struct()``, then its value must be given as a cell array,
150 %> with consecutive elements representing the struct ``property-name, property-value`` pairs.
151 %> Note that all of these property-value pairs can be also directly set via the
152 %> parent object attributes, before calling the ``make()`` method.
153 %>
154 %> \note
155 %> The input ``varargin`` can also contain the components
156 %> of the ``subplot`` component of the parent object.
157 %>
158 %> \interface{make}
159 %> \code{.m}
160 %>
161 %> tile = pm.vis.Tile(template, varargin);
162 %> tile.make(varargin);
163 %> tile.make();
164 %>
165 %> \endcode
166 %>
167 %> \example{make}
168 %>
169 %> t = pm.vis.Tile(pm.vis.SubplotLine());
170 %> t.make()
171 %>
172 %> \final{make}
173 %>
174 %> \author
175 %> \JoshuaOsborne, May 22 2024, 7:44 PM, University of Texas at Arlington<br>
176 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
177 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
178 function make(self, varargin)
179
180 self.premake(varargin{:});
181
182 %%%% First set the tile dimensions.
183
184 isEllipsoid = isa(self.template, "pm.vis.SubplotEllipse") || isa(self.template, "pm.vis.SubplotEllipse3");
186 if isEllipsoid
187
188 nplt = max(1, self.template.dimx, self.template.dimy);
189
190 else
191
192 lencolx = 0;
193 if isprop(self.template, "colx")
194 lencolx = pm.array.len(self.template.colx);
195 end
196
197 lencoly = 0;
198 if isprop(self.template, "coly")
199 lencoly = pm.array.len(self.template.coly);
200 end
201
202 lencolz = 0;
203 if isprop(self.template, "colz")
204 lencolz = pm.array.len(self.template.colz);
205 end
206
207 lencolc = 0;
208 if isprop(self.template, "colc")
209 lencolc = pm.array.len(self.template.colc);
210 end
211
212 nplt = max([lencolx, lencoly, lencolz, lencolc]);
213
214 end
215
216 %%%% Define the tile shape.
217
218 %self.tileshape = pm.matlab.hashmap.getKeyVal("tileshape", varargin);
219 if ~isempty(self.tileshape)
220 nrow = self.tileshape(1);
221 ncol = self.tileshape(2);
222 if prod(self.tileshape) < nplt
223 help("pm.vis.Tile");
224 disp("self.tileshape");
225 disp( self.tileshape );
226 disp("nplt");
227 disp( nplt );
228 error ( newline ...
229 + "The specified tile shape must be consistent" + newline ...
230 + "with the specified data columns to visualize." + newline ...
231 + newline ...
232 );
233 end
234 else
235 rows = nplt : -1 : 1;
236 cols = ceil(nplt ./ rows);
237 circ = rows + cols + (rows .* cols) - nplt;
238 [~, irow] = min(circ);
239 nrow = rows(irow);
240 ncol = cols(irow);
241 end
242
243 %if isempty(self.tileindex)
244 % tileindices = 1 : nplt;
245 %end
246
247 %%%% unified colorbar using tiledlayout is only possible in MARLAB R2020b and beyond.
248
249 unicbar = ~isEllipsoid ...
250 && lencolc == 1 ...
251 && isprop(self.template, "colorbar") ...
252 && isempty(self.template.colorbar.enabled) ...
253 && "2020a" < string(version('-release'));
254
255 %%%% Define the subplot cell matrix.
256 %%%% The following code block may be improved in
257 %%%% the future to avoid full data copy to subplots.
258
259 iplt = 0;
260 %tilecounter = 0;
261 self.subplot = cell(nrow, ncol);
262 for irow = 1 : nrow
263 for icol = 1 : ncol
264 %tilecounter = tilecounter + 1;
265 %if tilecounter == tileindices(iplt + 1)
266 iplt = iplt + 1;
267 if nplt < iplt
268 break;
269 end
270 %self.subplot{irow, icol} = self.template;
271 copyStream = getByteStreamFromArray(self.template);
272 self.subplot{irow, icol} = getArrayFromByteStream(copyStream);
273 if isEllipsoid
274 if ~isempty(self.template.subplot.dimx)
275 self.subplot{irow, icol}.dimx = self.template.dimx(min(iplt, numel(self.template.dimx)));
276 end
277 if ~isempty(self.template.subplot.dimy)
278 self.subplot{irow, icol}.dimy = self.template.dimy(min(iplt, numel(self.template.dimy)));
279 end
280 else
281 if 1 < lencolx
282 self.subplot{irow, icol}.colx = self.template.colx(iplt);
283 end
284 if 1 < lencoly
285 self.subplot{irow, icol}.coly = self.template.coly(iplt);
286 end
287 if 1 < lencolz
288 self.subplot{irow, icol}.colz = self.template.colz(iplt);
289 end
290 if 1 < lencolc
291 self.subplot{irow, icol}.colc = self.template.colc(iplt);
292 elseif unicbar
293 self.subplot{irow, icol}.colorbar.enabled = false;
294 elseif lencolc == 0 && isprop(self.template, "colormap") && isempty(self.template.colormap.enabled)
295 self.subplot{irow, icol}.colormap.enabled = true;
296 end
297 end
298 end
299 if nplt < iplt
300 break;
301 end
302 end
303
304 make@pm.vis.Tiling(self);
305
306 %%%% Define a single colorbar.
307
308 if unicbar && isprop(self.template, "colormap") && ~isempty(self.template.colormap.enabled)
309 unicbar = self.template.colormap.enabled;
310 end
311
312 if unicbar && isprop(self.template, "colorbar") && ~isempty(self.template.colorbar.enabled)
313 unicbar = self.template.colorbar.enabled;
314 end
315
316 if unicbar
317
318 %%%% Get the start and end positions of the leftmost, lowest, rightmost, and highest axes.
319
320 % iplt = 0;
321 % positions = zeros(4, nplt);
322 % for icol = 1 : ncol
323 % for irow = 1 : nrow
324 % if pm.introspection.istype(self.subplot{irow, icol}, "pm.vis.Subplot")
325 % iplt = iplt + 1;
326 % positions(:, iplt) = self.subplot{irow, icol}.fout.axes.Position;
327 % end
328 % end
329 % end
330 %
331 % for i = 2 : -1 : 1
332 % start(i) = min(positions(i, :));
333 % finit(i) = max(positions(i, :) + positions(i + 2, :));
334 % end
335
336 %%%% Create new invisible axes.
337
338 kws = struct();
339 for prop = [ "colorbar" ...
340 ]
341 if isprop(self.template, prop)
342 kws.(prop) = self.template.comp2hash(prop);
343 end
344 end
345
346 %ax = axes("position", [start, finit], "visible", "off");
347
348 self.fout.colorbar = colorbar(kws.colorbar{:});
349 self.fout.colorbar.Layout.Tile = 'east';
350 dfcopy = self.template.df.copy();
351 [~, colnamc] = pm.str.locname(dfcopy.Properties.VariableNames, self.template.colc);
352 ylabel(self.fout.colorbar, colnamc(1));
353
354 end
355
356 end % function
357
358 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
359
360 end
361
362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363
364 methods(Access = public, Hidden)
365
366 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
367
368 %> \brief
369 %> Configure the tile settings and specifications and return nothing.
370 %>
371 %> \warning
372 %> This method has side-effects by manipulating
373 %> the existing attributes of the parent object.
374 %>
375 %> \param[in] varargin : Any ``property, value`` pair of the parent object.<br>
376 %> If the property is a ``struct()``, then its value must be given as a cell array,
377 %> with consecutive elements representing the struct ``property-name, property-value`` pairs.
378 %> Note that all of these property-value pairs can be also directly set via the
379 %> parent object attributes, before calling the ``premake()`` method.
380 %>
381 %> \interface{premake}
382 %> \code{.m}
383 %>
384 %> tile = pm.vis.Tile(template, varargin);
385 %> tile.premake(varargin);
386 %> tile.premake();
387 %>
388 %> \endcode
389 %>
390 %> \example{getBorder}
391 %>
392 %> f = pm.vis.Tile(pm.vis.Line());
393 %> f.premake("figure", {"color", "none"})
394 %>
395 %> \final{premake}
396 %>
397 %> \author
398 %> \JoshuaOsborne, May 22 2024, 7:46 PM, University of Texas at Arlington<br>
399 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
400 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
401 function premake(self, varargin)
402
403 if ~isempty(varargin)
404 [varobj, vartemp] = pm.matlab.hashmap.popKeyVal(["figure", "subplot", "template", "tiledlayout", "tileshape"], varargin);
405 premake@pm.vis.Tiling(self, varobj{:});
406 self.template.hash2comp(vartemp);
407 %recursive = true;
408 %extensible = true;
409 %insensitive = true;
410 %self.template = pm.matlab.hashmap.hash2comp(vartemp, self.template, insensitive, extensible, recursive);
411 end
412
413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
414 %%%% These settings must happen here so that they can be reset every time user nullifies the values.
415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
416
417 end
418
419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
420
421 end
422
423 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
424
425end
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared libraries.
function list()
Return a list of MATLAB strings containing the names of OS platforms supported by the ParaMonte MATLA...
function version(in silent)
Return a scalar MATLAB string containing the latest available ParaMonte MATLAB version newer than the...
This is the abstract class for generating instances of axes with various types of plots from one or m...
Definition: Subplot.m:188
This is the abstract class for generating instances of objects that contain the specifications of var...
Definition: Tile.m:9
function make(in self, in varargin)
Configure the tile settings and specifications, make the tile, and return nothing.
function Tile(in template, in varargin)
Property template
Definition: Tile.m:20
Property tileshape
Definition: Tile.m:29
function reset(in self, in varargin)
Reset the properties of the tile to the original default settings. Use this method when you change ma...
function premake(in self, in varargin)
Configure the tile settings and specifications and return nothing.
This is the base class for generating instances of figures containing a tile of subplots.
Definition: Tiling.m:19
function clean()
Remove all paths that contain the ParaMonte lib directory from the MATLAB path variable.
function copy(in from, in to, in fields)
Copy the contents of the struct/object from to the struct/object to recursively and without destroyin...
function getBorder(in gramian, in center, in npnt)
Return a matrix of MATLAB doubles of shape [npnt, 2] containing the coordinates of a set of points on...
function getKeyVal(in key, in hashmap)
Return the value corresponding to the input key in the input hashmap cell array.
function hash2comp(in hashmap, in object, in insensitive, in extensible, in recursive)
Return a copy of the input object whose property (or field) values are overwritten with the correspon...
function istype(in varval, in vartype, in varsize)
Return true if and only if the input varval conforms with the specified input type vartype and the sp...
function len(in obj)
Return a scalar MATLAB whole-number containing the length of the input scalar or vector object.
function release(in type)
Return a scalar MATLAB string containing the MATLAB release version, year, or season as requested.
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...