2%> This is the abstract
class for generating instances of objects
3%> that contain the specifications of various types of Figures.<br>
6%> This is a
generic class for generating figures containing
7%> arbitrary number of subplots (to be added by the subclasses).<br>
10%> See the
list of
class attributes below,
11%> also those of the superclass [pm.matlab.Handle](@ref
Handle).<br>
14%> [pm.vis.Cascade](@ref
Cascade)<br>
15%> [pm.vis.Subplot](@ref
Subplot)<br>
16%> [pm.vis.Triplex](@ref
Triplex)<br>
17%> [pm.vis.Figure](@ref
Figure)<br>
18%> [pm.vis.Plot](@ref
Plot)<br>
19%> [pm.vis.Tile](@ref
Tile)<br>
24%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
25%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 properties(Access =
public)
34 %> A MATLAB ``
struct`` whose fields and their values will
35 %> be passed as keyword arguments to the MATLAB intrinsic ``figure``.<br>
36 %> The following are the
default components of ``figure``:<br>
39 %> <li> ``
name`` : Name of the figure, specified as a character vector or a
string scalar.<br>
40 %> <li> ``color`` : Background color, specified as an RGB triplet, a hexadecimal
41 %> color code, a color
name, or a
short name.<br>
42 %> If you specify ``
'none'``, the background color appears black on screen,
43 %> but
if you print the figure, the background prints as though the figure
44 %> window is transparent.<br>
45 %> <li> ``fileName`` : Character vector or
string scalar containing the file
name for
46 %> saving the figure specified as a character vector or a
string scalar.<br>
47 %> <li> ``position`` : Location and size of the drawable area, specified as
48 %> a vector of the form ``[left bottom width height]``.<br>
49 %> This area excludes the figure borders, title bar, menu bar, and tool bars.<br>
50 %> <li> ``units`` : Units of measurement, specified as one of the following values:<br>
51 %> ``
'pixels'`` | ``
'normalized'`` | ``
'inches'`` | ``
'centimeters'`` | ``
'points'`` | ``
'characters'``.<br>
52 %> The MATLAB documentation of the intrinsic ``figure``
for the meaning of the options.<br>
53 %> <li> ``others`` : See the acceptable keyword arguments of the MATLAB intrinsic ``figure()``.<br>
57 %> Keep in mind that MATLAB keyword arguments are
case-INsensitive.<br>
58 %> Hence, ensure you
do not add the same keyword as multiple different fields.<br>
59 %> For example, ``figure.color`` and ``figure.Color`` are the same,
60 %> and only one of the two will be processed.<br>
65 %> self.figure.units = pixels;
66 %> self.figure.color =
"none";
75 %> A MATLAB ``
struct`` whose fields are the outputs of
76 %> various plotting tools used to make the current axis.<br>
82 %> The scalar MATLAB logical (Boolean) indicator
which is ``
false`` by
default.<br>
83 %> If it is set to ``
true``, it will silence all output postprocessing messages (except warnings and errors).<br>
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 %properties(Access =
protected, Hidden)
91 % isdryrun =
true; % always
false after the first make() method call or reset().
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 methods(Access = public)
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 %> Construct and return an
object of class [pm.vis.figure.
Figure](@ref
Figure).<br>
104 %> This is the custom constructor of the class [pm.vis.figure.
Figure](@ref
Figure).<br>
106 %> \param[in] varargin : Any ``property, value`` pair of the parent
object.<br>
107 %> If the property is a ``struct()``, then its value must be given as a cell array,
108 %> with consecutive elements representing the struct ``property-
name, property-value`` pairs.<br>
109 %> Note that all of these property-value pairs can be also directly set via the
110 %> parent
object attributes, before calling the ``make()`` method.<br>
113 %> ``self`` : The output scalar
object of class [pm.vis.figure.
Figure](@ref
Figure).<br>
118 %> f = pm.vis.
figure.Figure();
119 %> f = pm.vis.figure.Figure(varargin);
124 %> \include{lineno} example/vis/figure/
Figure/main.m
126 %> \image html example/vis/figure/
Figure/
Figure.himmelblau.3d.png width=700
131 %> \JoshuaOsborne, May 21 2024, 12:06 AM, University of Texas at Arlington<br>
132 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
133 function self =
Figure(varargin)
135 self.reset(varargin{:});
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 %> Configure the figure settings and specifications,
142 %> make the figure, and
return nothing.<br>
145 %> This method has side-effects by manipulating
146 %> the existing attributes of the parent
object.<br>
148 %> \param[inout] self : The input/output parent
object of
class [pm.vis.figure.Figure](@ref
Figure)
149 %>
which is **implicitly** passed to
this dynamic method (not by the user).<br>
150 %> \param[in] varargin : Any ``property, value`` pair of the parent
object.<br>
151 %> If the
property is a ``
struct()``, then its value must be given as a cell array,
152 %> with consecutive elements representing the
struct ``property-
name, property-value`` pairs.<br>
153 %> Note that all of these property-value pairs can be also directly set via the
154 %> parent
object attributes, before calling the ``make()`` method.<br>
159 %> f = pm.vis.figure.Figure.make(varargin);
165 %> \include{lineno} example/vis/figure/
Figure/main.m
167 %> \image html example/vis/figure/
Figure/
Figure.himmelblau.3d.png width=700
172 %> \JoshuaOsborne, May 21 2024, 8:09 AM, University of Texas at Arlington<br>
173 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
174 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
175 function make(self, varargin)
179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180 %%%% RULE 0: No component of ``self`` is allowed to appear to the left of assignment
operator, except ``fout``.
181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 %%%% Get keyword arguments.
188 for prop = [
"figure" ...
190 if isprop(self, prop)
191 kws.(prop) = self.comp2hash(prop);
195 self.fout.figure = figure(kws.figure{:});
196 %hold on; This interferes with Heatmap plots.
199 %%%% Resize the figure to allow good
default visualization.
202 if isempty(self.figure.outerPosition)
203 maxSize = get(0, 'ScreenSize');
204 figSize = self.fout.figure.OuterPosition;
205 figStart = [(maxSize(3) - figSize(3)) / 2, (maxSize(4) - figSize(4)) / 2];
206 set(self.fout.figure, "OuterPosition", [figStart(1:2), figSize(3:4)]);
211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214 %> Reset the properties of the figure to the original default settings.<br>
217 %> Use this method when you change many attributes of the plot and
218 %> you want to
clean up and go back to the default settings.<br>
220 %> \param[inout] self : The input/output parent
object of class [pm.vis.figure.
Figure](@ref
Figure)
221 %>
which is **implicitly** passed to this dynamic method (not by the user).<br>
222 %> \param[in] varargin : Any ``property, value`` pair of the parent
object.<br>
223 %> If the property is a ``struct()``, then its value must be given as a cell array,
224 %> with consecutive elements representing the struct ``property-
name, property-value`` pairs.<br>
225 %> Note that all of these property-value pairs can be also directly set via the
226 %> parent
object attributes, before calling the ``make()`` method.<br>
231 %> pm.vis.figure.Figure.reset() % reset the plot to the
default settings.
238 %> \JoshuaOsborne, May 21 2024, 8:11 AM, University of Texas at Arlington<br>
239 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
240 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
241 function reset(self, varargin)
243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 %%%% RULE 0: Any non-MATLAB-
default setting must be preferably set in premake() method to override user null values.
245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 self.figure.alphamap = [];
248 self.figure.color = "white";
249 self.figure.colormap = [];
250 self.figure.fileName = [];
251 self.figure.innerPosition = [];
252 self.figure.
name = [];
253 self.figure.numberTitle = [];
254 self.figure.outerPosition = [];
255 self.figure.position = [];
256 self.figure.resize = [];
257 self.figure.units = [];
258 self.figure.visible = [];
259 self.figure.windowState = [];
260 if ~isempty(varargin)
261 self.
hash2comp(varargin); % parse arguments
266 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
272 methods(Access = public, Hidden)
274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277 %> Configure the figure settings and specifications and return nothing.<br>
280 %> This method has side-effects by manipulating
281 %> the existing attributes of the parent
object.<br>
283 %> \param[inout] self : The input/output parent
object of class [pm.vis.figure.
Figure](@ref
Figure)
284 %>
which is **implicitly** passed to this dynamic method (not by the user).<br>
285 %> \param[in] varargin : Any ``property, value`` pair of the parent
object.<br>
286 %> If the property is a ``struct()``, then its value must be given as a cell array,
287 %> with consecutive elements representing the struct ``property-
name, property-value`` pairs.<br>
288 %> Note that all of these property-value pairs can be also directly set via the
289 %> parent
object attributes, before calling the ``premake()`` method.<br>
291 %> \interface{premake}
294 %> f = pm.vis.figure.Figure(varargin);
295 %> f.premake(varargin);
302 %> f = pm.vis.figure.Figure();
303 %> f.premake(
"figure", {
"color",
"none"})
310 %> \JoshuaOsborne, May 21 2024, 8:13 AM, University of Texas at Arlington<br>
311 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
312 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
313 function premake(self, varargin)
315 if ~isempty(varargin)
316 self.hash2comp(varargin); % parse arguments
319 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
320 %%%% These settings must happen here so that they can be reset every time user nullifies the values.
321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325 %
if isfield(self.figure,
"color") && pm.array.len(self.figure.color) == 0
326 % self.figure.color =
"none";
331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334 %> Convert the components of the input component ``comp``
335 %> of the parent
object into a cell array of key-val pairs.<br>
338 %> This is a dynamic method of the
class [pm.vis.figure.Figure](@ref
Figure).<br>
339 %> This method is used internally by the subclasses to convert the parent
object
340 %> attributes to input arguments of MATLAB intrinsic visualization functions.<br>
342 %> \param[inout] self : The input/output parent
object of
class [pm.vis.figure.Figure](@ref
Figure)
343 %>
which is **implicitly** passed to
this dynamic method (not by the user).<br>
344 %> \param[in] comp : The input scalar MATLAB
string representing the
name of a ``
struct``
345 %> component of the parent object, whose fields names and values are to
346 %> be returned as subsequent pairs in the output ``hash`` cell array.<br>
349 %> ``hash`` : The output cell array containing the pairs of ``field-
name, field-value``
350 %> of the input MATLAB
struct ``comp``.<br>
352 %> \interface{comp2hash}
355 %> a = pm.vis.figure.Figure(varargin);
356 %> hash = a.comp2hash(comp);
361 %> This method has side-effects by manipulating
362 %> the existing attributes of the parent
object.<br>
364 %> \example{comp2hash}
367 %> a = pm.vis.figure.Figure(
"figure", {
"color",
"white"});
368 %> hash = a.comp2hash(
"figure");
375 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
376 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
377 function hash = comp2hash(self, comp)
380 excludes = {
"enabled"};
381 hash = pm.matlab.hashmap.struct2hash(self.(comp), excludes, unique, onlyfull);
384 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
390 methods(Access =
public)
393 %> Export the current figure to the specified external file.<br>
396 %> This method internally uses the venerable ``export_fig`` MATLAB package.<br>
397 %> As such, it accepts all arguments that the ``export_fig()`` function accepts.<br>
398 %> If no optional argument is present, then a
default set of options determined
399 %> by the ``export_fig`` library will be used.<br>
401 %> \param[inout] self : The input/output parent
object of
class [pm.vis.figure.Figure](@ref
Figure)
402 %>
which is **implicitly** passed to
this dynamic method (not by the user).<br>
403 %> \param[in] file : The input scalar MATLAB
string or
char vector containing
404 %> the path to the external file that will contain the visualization.<br>
405 %> The specified file extension determines its type (e.g., ``.pdf``, ``.png``).<br>
406 %> If no file extension is specified, then the
default ``.png`` file extension is used.<br>
407 %> (**optional**. If ``file`` is missing or empty, first, the ``fileName`` component of
408 %> the ``figure``
property of the parent
object will be used as the filename
if not empty.<br>
409 %> Otherwise, the figure will be exported to a file in the current working directory of
410 %> MATLAB with
name ``figure`` suffixed by a unique number and ``.png`` extension.)
411 %> \param[in] varargin : The following optional flags are also acceptable as input
string arguments.<br>
412 %> This method internally uses the venerable ``export_fig`` MATLAB package.<br>
413 %> As such, it accepts all arguments that the ``export_fig()`` function accepts.<br>
414 %> If no optional argument is present, then a
default set of options determined
415 %> by the ``export_fig`` library will be used.<br>
416 %> The recommended set of optional flags
for PNG file formats is ``
"-m4 -transparent"``.<br>
418 %> <li> ``
"-<format>"``
420 %> The input scalar (or variadic array of) MATLAB string(s)
421 %> containing the output file extension(s). Options include:
435 %> Multiple formats can be specified, without restriction.<br>
440 %>
savefig(
'-jpg',
'-pdf',
'-png')
444 %> Note that ``
'-tif'`` and ``
'-tiff'`` are equivalent.<br>
446 %> <li> ``
"-transparent"``
448 %> The input option indicating that the figure background is to
449 %> be made transparent (PNG, PDF, TIF, EPS, EMF formats only).<br>
450 %> Specifying
this option also activates ``
"-noinvert"``.<br>
452 %> <li> ``
"-nocrop"``
454 %> The input option indicating that empty margins should not be cropped.<br>
456 %> <li> ``
"-c[<val>,<val>,<val>,<val>]"``
458 %> The input option indicating the crop amounts. It must be
459 %> a 4-element vector of numeric values: ``[top, right, bottom, left]``
460 %> where NaN/Inf indicates
auto-cropping, 0 means no cropping, any
461 %> other value means cropping in pixel amounts. e.g. ``
'-c7,15,0,NaN'``
462 %> Note that
this option is not supported by SVG and EMF formats.<br>
464 %> <li> ``
"-p<val>"``
466 %> The input option to pad a border of width ``val`` to exported files,
467 %> where ``val`` is either a relative size with respect to cropped image
468 %> size (i.e. ``p = 0.01`` adds a ``1%`` border). For EPS & PDF formats,
469 %> ``val`` can also be integer in units of ``1/72`` points (``
abs(val) > 1``).<br>
470 %> ``val`` can be positive (padding) or negative (extra cropping).<br>
471 %> If used, the ``-nocrop`` flag will be ignored, i.e. the image will
472 %> always be cropped and then padded. Default: ``0`` (i.e. no padding).<br>
473 %> Note:
this option is not supported by SVG and EMF formats.<br>
475 %> <li> ``
"-m<val>"``
477 %> The input option ``val`` indicates the factor to magnify the figure
478 %> dimensions when generating bitmap outputs (does not affect vector formats).<br>
479 %> Default:
'-m1' (i.e. val=1). Note: val~=1 slows down
savefig.<br>
481 %> <li> ``
"-r<val>"``
483 %> The input option ``val`` indicates the resolution (in pixels per inch)
484 %> to export bitmap and vector outputs, without changing dimensions of
485 %> the on-screen figure. Default:
'-r864' (
for vector output only).<br>
486 %> Note: -m option overides -r option
for bitmap exports only.<br>
488 %> <li> ``
"-native"``
490 %> The input option indicating that the output resolution (when
491 %> outputting a bitmap format) should be such that the vertical
492 %> resolution of the first suitable image found in the figure is
493 %> at the native resolution of that image. To specify a particular
494 %> image to use, give it the tag
'export_fig_native'.<br>
495 %> Notes: This overrides any value set with the -m and -r options.<br>
496 %> It also assumes that the image is displayed front-to-
parallel
497 %> with the screen. The output resolution is approximate and
498 %> should not be relied upon. Anti-aliasing can have adverse
499 %> effects on image quality (disable with the -a1 option).<br>
501 %> <li> ``
"-a1, -a2, -a3, -a4"``
503 %> The input option indicating the amount of anti-aliasing (AA) to
504 %> use
for bitmap outputs, when GraphicsSmoothing is not available.<br>
505 %>
'-a1'=no AA;
'-a4'=max. Default: 3
for HG1, 1
for HG2.<br>
507 %> <li> ``
"-<renderer>"``
509 %> The input option to force a particular renderer (painters, opengl or
510 %> [in R2014a or older] zbuffer). Default value: opengl
for bitmap
511 %> formats or figures with patches and/or transparent annotations;
512 %> painters
for vector formats without patches/transparencies.<br>
514 %> <li> ``
"-<colorspace>"``
516 %> The input option indicating
which colorspace color figures should
517 %> be saved in: RGB (
default), CMYK or gray. Usage example:
'-gray'.<br>
518 %> Note: CMYK is only supported in PDF, EPS and TIF formats.<br>
520 %> <li> ``
"-q<val>"``
522 %> The input option to vary bitmap image quality (PDF, EPS, JPG formats only).<br>
523 %> A larger val, in the range 0-100, produces higher quality and
524 %> lower compression. val > 100 results in lossless compression.<br>
525 %> Default:
'-q95' for JPG,
ghostscript prepress
default for PDF,EPS.<br>
526 %> Note: lossless compression can sometimes give a smaller file size
527 %> than the
default lossy compression, depending on the image type.<br>
529 %> <li> ``
"-n<val>"``
531 %> The input option to set minimum output image size (bitmap formats only).<br>
532 %> The output size can be specified as a single value (
for both rows
533 %> & cols, e.g. ``-n200``) or comma-separated values (e.g. ``-n300,400``).<br>
534 %> Use an Inf value to keep a dimension unchanged (e.g. ``-n50,inf``).<br>
535 %> Use a NaN value to keep aspect ratio unchanged (e.g. ``-n50,nan``).<br>
537 %> <li> ``
"-x<val>"``
539 %> The input option to set maximum output image size (bitmap formats only).<br>
540 %> The output size can be specified as a single value (
for both rows
541 %> & cols, e.g. ``-x200``) or comma-separated values (e.g. ``-x300,400``).<br>
542 %> Use an Inf value to keep a dimension unchanged (e.g. ``-x50,inf``).<br>
543 %> Use a NaN value to keep aspect ratio unchanged (e.g. ``-x50,nan``).<br>
545 %> <li> ``
"-s<val>"``
547 %> The input option to scale output image to specific size (bitmap formats only).<br>
548 %> The fixed size can be specified as a single value (
for rows=cols) or
549 %> comma-separated values (e.g. ``-s300,400``). Each value can be a scalar
550 %> integer (signifying pixels) or percentage (e.g. ``-s125%``). The scaling
551 %> is done last, after any other cropping/rescaling due to other params.<br>
553 %> <li> ``
"-append"``
555 %> The input option indicating that
if the file already exists the figure is to
556 %> be appended as a
new page, instead of being overwritten (
default).<br>
557 %> PDF, TIF & GIF output formats only (multi-image GIF = animated).<br>
559 %> <li> ``
"-bookmark"``
561 %> The input option to indicate that a bookmark with the
name of the
562 %> figure is to be created in the output file (PDF format only).<br>
564 %> <li> ``
"-clipboard"``
566 %> The input option to save output as an image on the system clipboard.<br>
568 %> <li> ``
"-clipboard<:format>"``
570 %> The input copies to clipboard in the specified format:
571 %> image (
default), bitmap, emf, or pdf.<br>
572 %> Notes that only ``-clipboard`` (or ``-clipboard:image``,
which is the same)
573 %> applies export_fig parameters such as cropping, padding etc.
575 %> <li> ``-clipboard:image`` create a bitmap image
using export_fig processing
576 %> <li> ``-clipboard:bitmap`` create a bitmap image as-is (no
auto-cropping etc.)
577 %> <li> ``-clipboard:emf`` is vector format without
auto-cropping; Windows-only.
578 %> <li> ``-clipboard:pdf`` is vector format without cropping; not universally supported
581 %> <li> ``
"-d<gs_option>"``
583 %> The input option to indicate a
ghostscript setting. For example,
584 %> ``-dMaxBitmap=0`` or ``-dNoOutputFonts`` (Ghostscript 9.15+).<br>
588 %> The input option to use EPS level-3 rather than the
default level-2 print
589 %> device. This solves some bugs with MATLAB
's default -depsc2 device
590 %> such as discolored subplot lines on images (vector formats only).<br>
592 %> <li> ``"-metadata <metaDataInfo>"``
594 %> The input adds the specified meta-data information to the
595 %> exported file (PDF format only). metaDataInfo must be either a struct
596 %> or a cell array with pairs of values: ``{'fieldName
', fieldValue, ...}``.<br>
597 %> Common metadata fields are Title, Author, Creator, Producer, Subject, Keywords.<br>
599 %> <li> ``"-nofontswap"``
601 %> The input option to avoid font swapping. Font swapping is automatically
602 %> done in vector formats (only): 11 standard MATLAB fonts are
603 %> replaced by the original figure fonts. This option prevents this.<br>
605 %> <li> ``"-font_space <char>"``
607 %> The input option to set a spacer character for font-names that
608 %> contain spaces, used by EPS/PDF. Default: ''<br>
610 %> <li> ``"-linecaps"``
612 %> The input option to create rounded line-caps (vector formats only).<br>
614 %> <li> ``"-noinvert"``
616 %> The input option to avoid setting figure's InvertHardcopy property to
617 %>
'off' during output (
this solves some problems of empty outputs).<br>
619 %> <li> ``
"-preserve_size"``
621 %> The input option to preserve the figure
's PaperSize property in output
622 %> file (PDF/EPS formats only; default is to not preserve it).<br>
624 %> <li> ``"-options <optionsStruct>"``
626 %> The input format-specific parameters as defined in MATLAB's
627 %> documentation of the ``imwrite`` function, contained in a
struct under
628 %> the format
name. For example to specify the JPG Comment parameter,
629 %> pass a
struct such as this: ``options.JPG.Comment='abc'``.<br>
630 %> Similarly, ``options.PNG.BitDepth = 4``.<br>
631 %> Only used by PNG, TIF, JPG, GIF output formats.<br>
632 %> Options can also be specified as a cell array of
name-value pairs,
633 %> e.g. ``{
'BitDepth', 4,
'Author',
'Yair'}``. These options will be used
634 %> by all supported output formats of the [pm.vis.figure.savefig](@ref
savefig) function.<br>
636 %> <li> ``
"-silent"``
638 %> The input option to avoid various warning and informational messages,
639 %> such as
version update checks, transparency or renderer issues, etc.<br>
641 %> <li> ``
"-notify"``
643 %> The input option to notify the user when export is done, in both a console
644 %> message and a popup dialog (allow opening the exported file/folder).<br>
646 %> <li> ``
"-regexprep <old> <new>"``
648 %> The input replaces all occurrences of ``<old>`` (a regular expression
649 %>
string or array of strings;
case-sensitive), with the corresponding
650 %>
new string(s), in EPS/PDF files (only). See regexp function
's doc.<br>
651 %> Warning: invalid replacement can make your EPS/PDF file unreadable!<br>
653 %> <li> ``"-toolbar"``
655 %> The input adds an interactive export button to the figure's toolbar<br>
657 %> <li> ``
"-menubar"``
659 %> The input adds an interactive export menu to the figure
's menubar<br>
661 %> <li> ``"-contextmenu"``
663 %> The input adds interactive export menu to figure context-menu (right-click)<br>
665 %> <li> ``"handle"``<br>
667 %> The input handle of the figure, axes or uipanels (can be an array of handles
668 %> but all the objects must be in the same figure) to be exported.<br>
669 %> The default is ``gcf`` (handle of current figure).<br>
671 %> <li> ``"figName"``
673 %> The input name (title) of the figure to export (e.g. ``'Figure 1'`` or ``
'My fig'``).<br>
674 %> Overridden by handle (
if specified)<br>
675 %> The
default is the current figure.<br>
679 %> ``imageData`` : The output image cube of type ``uint8`` of
680 %> shape ``[M, N, C]`` containing the exported figure data.<br>
681 %> ``alpha`` : The output image matrix of shape ``[M, N]`` of alpha-matte
682 %> values in the range ``[0, 1]``
for the
case of transparent background.<br>
687 %> f = pm.vis.figure.Figure();
688 %> [imageData, alpha] = f.savefig();
689 %> [imageData, alpha] = f.savefig(file);
690 %> [imageData, alpha] = f.savefig(file, varargin{:});
697 %> f = pm.vis.figure.Figure();
698 %> f.savefig(); % export the current figure with the
default name.
699 %> f.savefig(
"gridplot.pdf") % export figure to the specified PDF file.
700 %> f.savefig(
"gridplot.png",
"-m4 -transparent") % export a large png plot of magnitude 4 with transparency.
707 %> \JoshuaOsborne, May 21 2024, 8:19 AM, University of Texas at Arlington<br>
708 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
709 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
710 function
savefig(self, file, varargin)
715 if pm.array.len(file) == 0
716 if ~isempty(self.figure.fileName)
717 file =
string(self.figure.fileName);
719 if ~isempty(self.figure.
name)
720 prefix =
string(self.figure.
name);
727 file = prefix + "." +
string(fid) + ".png";
736 %%%% Check the consistency of the file
name.
739 if ~pm.introspection.
istype(file, "
string", 1)
740 help("pm.vis.figure.
Figure");
744 + "The optional input argument ``file`` to method ``
savefig()``" + newline ...
745 + "must be a scalar MATLAB
string or
char vector containing the output file
name." + newline ...
746 + "For more information, see the class documentation displayed above." + newline ...
752 %%%% Focus on the target figure to export.
755 if isfield(self.fout, "figure")
756 set(0, "CurrentFigure", self.fout.figure);
758 set(0, "CurrentFigure", gcf);
762 %%%% Ensure transparency if figure must be transparent.
765 if any(contains(
string(varargin), "-transparent"))
766 istransparent = true;
770 set(self.fout.figure, "color", "none");
773 errmsg =
string(me.identifier) + " : " +
string(me.message) + newline;
776 set(gca, "color", "none");
779 errmsg =
string(me.identifier) + " : " +
string(me.message) + newline;
782 warning ( newline + errmsg ...
783 + "Failed to set the color property of gcf to ""none"" for transparent image export." + newline ...
787 istransparent = false;
790 pm.vis.figure.
savefig(file, varargin{:});
793 %%%% Revert transparency
if figure ws not transparent.
800 set(self.currentFig.figure,
"color",
"default");
803 errmsg = string(me.identifier) +
" : " + string(me.message) + newline;
806 set(gca,
"color",
"default");
809 errmsg = string(me.identifier) +
" : " + string(me.message) + newline;
812 warning ( newline + errmsg ...
813 +
"Failed to set the color property of gca back to ""default""." + newline ...
822 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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...
function abs(in path, in style)
Return the Get absolute canonical path of a file or folder.
This is the abstract class for generating instances of objects that contain the specifications of a c...
This is the base class for generating subclass of MATLAB handle superclass whose annoying methods are...
This is the base class for generating instances of objects that contain the specifications of various...
This is the abstract class for generating instances of axes with various types of plots from one or m...
This is the abstract class for generating instances of objects that contain the specifications of var...
This is the base class for generating instances of figures containing a square symmetric tiling of su...
function clean()
Remove all paths that contain the ParaMonte lib directory from the MATLAB path variable.
function ghostscript(in cmd)
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 parallel()
Return a scalar MATLAB logical that is true if and only if the current installation of MATLAB contain...
function savefig(in varargin)
Export figures in a publication-quality format.
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...