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