KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PlotManager.m
Go to the documentation of this file.
1 
2 
3 /* (Autoinserted by mtoc++)
4  * This source code has been filtered by the mtoc++ executable,
5  * which generates code that can be processed by the doxygen documentation tool.
6  *
7  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
8  * Except for the comments, the function bodies of your M-file functions are untouched.
9  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
10  * attached source files that are highly readable by humans.
11  *
12  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
13  * the correct locations in the source code browser.
14  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
15  */
16 
18  :public handle {
107  public:
108 
109  logical Single = true;
157  integer ExportDPI = get("0,'ScreenPixelsPerInch'");
210  SaveFont = struct("'FontWeight','bold','FontSize',16");
211 
212 
224  cell<char> SaveFormats = {"'jpg'"};
279  private:
280 
281  rows = 0;
282 
283  cols = 0;
284 
285 
286  public: /* ( Transient ) */
287 
303  private: /* ( Transient ) */
304 
305  curax = "[]";
306 
307  fignr;
308 
309  cnt;
310 
311  ss;
312 
313  ncap = "[]";
324  nxl = "[]";
325 
326  nyl = "[]";
327 
328  nleg = "[]";
329 
330  donelast = false;
331 
332 
333  public: /* ( Transient ) */
334 
335  PlotManager(logical single,integer rows,integer cols) {
336  if nargin > 0
337  this.Single= single;
338  if nargin > 1
339  this.rows= rows;
340  this.cols= cols;
341  elseif ~this.Single
342  this.rows= 2;
343  this.cols= 2;
344  end
345  end
346  this.cnt= 0;
347  this.fignr= 0;
348  this.Figures= [];
349  s = get(0," MonitorPositions ");
350  this.ss= s(1,3:4);
351  }
365  function axesax_handle = nextPlot(char tag,char caption,char xlab,char ylab,cell<char> leg_str,integer numsubplots) {
366  if nargin < 6
367  leg_str = [];
368  if nargin < 5
369  ylab = [];
370  if nargin < 4
371  xlab =[];
372  if nargin < 3
373  caption = [];
374  if nargin < 2
375  tag = ;
376  end
377  end
378  end
379  end
380  end
381  /* Fix stupid latex cant find image because there's a dot in the
382  * filename bug */
383  tag = strrep(tag," . "," _ ");
384  /* Finish current plot */
385  this.finishCurrent;
386  /* Store caption etc for upcoming plot */
387  this.ncap= caption;
388  this.nxl= xlab;
389  this.nyl= ylab;
390  this.nleg= leg_str;
391 
392  if ~isempty(this.FigureSize)
393  fpos = [(this.ss - this.FigureSize)/2 this.FigureSize];
394  else
395  fpos = get(0," DefaultFigurePosition ");
396  end
397  if this.Single
398  this.Figures(end+1) = figure(" Position ",fpos," Tag ",tag,...
399  " Units "," pixels ");
400  ax_handle = gca;
401  else
402  if nargin < 7
403  numsubplots = 1;
404  end
405  this.cnt= this.cnt + numsubplots;
406  if isempty(this.Figures) || this.cnt > this.rows*this.cols
407  this.nextFigure(numsubplots," Position ",fpos," Tag ",tag,...
408  " Units "," pixels ");
409  else
410  /* Re-Focus on last figure to always correctly continue
411  * filling in plots */
412  if gcf ~= this.Figures(end)
413  figure(get(this.curax," Parent "));
414  end
415  end
416  ax_handle = subplot(this.rows, this.cols, ...
417  (this.cnt-numsubplots+1):this.cnt, " Tag ", tag);
418  end
419  this.curax= ax_handle;
420  this.donelast= false;
421  }
448  function h = copyFigure(nr,newtag) {
449  if isempty(this.Figures)
450  fprintf(2," No figures exist yet within the PlotManager. Nothing to copy.\n ");
451  return;
452  elseif ~this.Single
453  error(" copyFigure works only in single plot mode. ");
454  end
455  if nargin < 2
456  nr = length(this.Figures);
457  elseif isempty(nr) || ~isposintscalar(nr) || nr > length(this.Figures)
458  error(" nr must not be empty and within the range 1 to %d ",length(this.Figures));
459  end
460  s = this.Figures(nr);
461  if nargin < 3
462  newtag = [get(s," Tag ") " _copy "];
463  end
464  f = figure(" Position ",get(s," Position ")," Tag ",newtag);
465  this.Figures(end+1) = f;
466  /* Copy stuff over */
467  h = copyobj(get(s," Children "),f);
468  h = findobj(h," Tag ",," Type "," axes ");
469  }
479  function h = createZoom(nr,area,tagextra,withlegend) {
480  if nargin < 5
481  withlegend = false;
482  if nargin < 4
483  tagextra = ;
484  end
485  end
486  if ~isempty(tagextra)
487  tagextra = [" _ " tagextra];
488  end
489  if numel(area) == 2
490  area = [reshape(area,1,2) NaN NaN];
491  end
492 
493  if ~this.Single
494  error(" Zooming only possible for Single mode yet. ");
495  elseif isempty(nr) || ~isposintscalar(nr) || nr > length(this.Figures)
496  error(" nr must not be empty and within the range 1 to %d ",length(this.Figures));
497  end
498  /* Creates a new figure and returns the axes handle */
499  h = this.copyFigure(nr,[get(this.Figures(nr)," Tag ") " _zoom " tagextra]);
500  /* Set to desired area */
501  useold = isnan(area);
502  area(useold) = 0; /* set NaNs to values (otherwise 0*NaN = NaN) */
503 
504  oldarea = [get(h," XLim ") get(h," YLim ")];
505  area = useold.*oldarea + (~useold).*area;
506  axis(h, area);
507  if ~withlegend
508  delete(findobj(get(this.Figures(end)," Children ")," Tag "," legend "));
509  end
510  /* Check correct Y tickmarks */
511  this.checkTickMarks(h);
512  }
513 
514 
515  function done() {
516  this.finishCurrent;
517  this.cnt= 0;
518  }
529  function savePlots(char folder,varargin) {
530 
531 
532  ip.addParamValue('Format',this.SaveFormats,@(arg)(ischar(arg) || iscellstr(arg)) && ~isempty(arg));
533  ip.addParamValue('Close',false,@islogical);
534  ip.addParamValue('Selection',1:length(this.Figures),@isvector);
535  ip.addParamValue('SeparateLegends',false,@(arg)islogical(arg) && isvector(arg));
536  ip.addParamValue('XArgs',{},@iscellstr);
537  if nargin < 2
538  folder = pwd;
539  end
540  if exist(folder," file ") ~= 7
541  mkdir(folder);
542  end
543  ip.parse(varargin[:]);
544  res = ip.Results;
545  selection = res.Selection;
546  separate_legends = res.SeparateLegends;
547  if isscalar(separate_legends)
548  separate_legends = repmat(separate_legends,1,length(selection));
549  elseif ~all(size(selection) == size(separate_legends))
550  error(" If a separate legends parameter is passed, it must match the selection parameter size. ");
551  end
552  format = res.Format;
553  if ischar(format)
554  format = [format];
555  end
556 
557  /* Make sure the last plot has been finished off before saving
558  * it. */
559  this.finishCurrent;
560 
561  n = length(selection);
562  fmtstr = format[1];
563  if length(format) > 1
564  fmtstr = [sprintf(" %s, ",format[1:end-1]) format[end]];
565  end
566  fprintf(" Saving %d current figures as '%s' in %s... ", n, fmtstr, folder);
567  for idx=1:n
568  h = this.Figures(selection(idx));/* #ok<*PROP> */
569 
570  if ishandle(h)
571  fname = get(h," Tag ");
572  /* check for empty tags here as people may have changed
573  * the tag some place else in between */
574  if isempty(fname)
575  fname = sprintf(" figure_%d ",idx);
576  end
577  [oldtitles, oldfonts] = this.preSave(h);
578  /* Separate legend saving */
579  legends = [];
580  if separate_legends(idx)
581  legends = findobj(h," tag "," legend ");
582  lfh = zeros(1,length(legends));
583  for lidx = 1:length(legends)
584  lfh(lidx) = figure(" Visible "," off "," MenuBar "," none ");
585  newlh = copyobj(legends(lidx),lfh(lidx));
586  set(newlh," Box "," off ");
587  set(legends(lidx)," Visible "," off ");
588  end
589  if isempty(legends)
590  warning(" PlotManager:savePlots ",...
591  " No legends found for Figure %d. ",selection(idx));
592  end
593  end
594 
595  /* Add prefix if set */
596  if ~isempty(this.FilePrefix)
597  fname = [this.FilePrefix " _ " fname];
598  end
599  this.saveFigure(h, fullfile(folder, fname), format, res.XArgs);
600  /* Save extra legends (if given) */
601  for lidx = 1:length(legends)
602  this.saveFigure(lfh(lidx), ...
603  fullfile(folder, sprintf(" %s_legend%d ",fname, lidx)),...
604  format, res.XArgs);
605  end
606 
607  /* Move created images to own folders if wanted */
608  if this.UseFileTypeFolders
609  for fmt = 1:length(format)
610  if exist(fullfile(folder,format[fmt])," file ") ~= 7
611  mkdir(fullfile(folder,format[fmt]));
612  end
613  fn = [fname " . " format[fmt]];
614  /* Move to format-specific folder */
615  movefile(fullfile(folder, fn), fullfile(folder,format[fmt],fn));
616  /* Move extra legends (if given) */
617  for lidx = 1:length(legends)
618  fn = sprintf(" %s_legend%d.%s ", fname, lidx, format[fmt]);
619  movefile(fullfile(folder, fn), fullfile(folder,format[fmt],fn));
620  end
621  end
622  end
623 
624 /* % Quick fix: Repeat save process for JPG figures if desired
625  * if this.DoubleSaveJPG && strcmp(format{fmt},'jpg')
626  * % Save actual figure
627  * this.saveFigure(h, ...
628  * fullfile(eff_folder, eff_name), ...
629  * format{fmt});
630  * % Save extra legends (if given)
631  * for lidx = 1:length(legends)
632  * this.saveFigure(lfh(lidx), ...
633  * fullfile(eff_folder, ...
634  * sprintf('%s_legend%d',eff_name,lidx)), ...
635  * format{fmt});
636  * end
637  * end */
638 
639  /* Restore visibility of perhaps hidden legends and close temporary figures */
640  for lidx = 1:length(legends)
641  set(legends(lidx)," Visible "," on ");
642  close(lfh(lidx));
643  end
644  this.postSave(h, oldtitles, oldfonts);
645  else
646  fprintf(2," Warning: figure handle %d is invalid. Did you close it? ",...
647  selection(idx));
648  end
649  end
650  fprintf(" done!\n ");
651  if res.Close
652  this.closeAll(selection);
653  end
654  }
680  function closeAll(selection) {
681  if nargin < 2
682  selection = 1:length(this.Figures);
683  end
684  for i=1:length(selection)
685  h = this.Figures(selection(i));
686  if ishandle(h) && strcmp(get(h," Type ")," figure ")
687  close(h);
688  end
689  end
690  if ~isempty(this.curax) && ishandle(this.curax) && strcmp(get(this.curax," Type ")," figure ")
691  close(this.curax);
692  this.curax= [];
693  end
694  this.Figures(selection) = [];
695  this.fignr= 0;
696  this.cnt= 0;
697  }
706  function resetCount() {
707  this.finishCurrent;
708  this.cnt= 0;
709  }
717  function delete() {
718  if ~this.LeaveOpen
719  this.closeAll;
720  end
721  }
722 
723 
724  function setFigureNames(name) {
725  for i=1:length(this.Figures)
726  h = this.Figures(i);
727  if ishandle(h) && strcmp(get(h," Type ")," figure ")
728  set(h," Name ",name);
729  end
730  end
731  }
732 
733 
734  function matchPlotAxes(ax_handles,varargin) {
735 
736  ip.addParamValue('Axis','YLim',@(arg)(ischar(arg)) && any(strcmp(arg,{'XLim','YLim','ZLim'})));
737  /* ip.addParamValue('Selection',1:length(this.Figures),@isvector); */
738  ip.parse(varargin[:]);
739  res = ip.Results;
740  lim = get(ax_handles(1),res.Axis);
741  for k = 2:numel(ax_handles)
742  tmp = get(ax_handles(k),res.Axis);
743  lim(1) = min(lim(1),tmp(1));
744  lim(2) = max(lim(2),tmp(2));
745  end
746  for k = 1:numel(ax_handles)
747  set(ax_handles, res.Axis, lim);
748  end
749  }
750 
751 
752  /* % Getter & Setter */
753  public: /* ( Transient ) */
754 
755 
756 #if 0 //mtoc++: 'set.SaveFormats'
757 function SaveFormats(value) {
758  if ~iscellstr(value)
759  if ischar(value)
760  value = [value];
761  else
762  error(" SaveFormats must be a cell of strings. ");
763  end
764  end
765  this.SaveFormats= value;
766  }
767 
768 #endif
769 
770 
771 
772 #if 0 //mtoc++: 'set.ExportDPI'
773 function ExportDPI(value) {
774  if ~isposintscalar(value)
775  error(" ExportDPI must be a positive integer. ");
776  end
777  this.ExportDPI= value;
778  }
779 
780 #endif
781 
782 
783 
784  private: /* ( Transient ) */
785 
786 
787  function fh = nextFigure(numsubplots,varargin) {
788  if this.fignr+1 > this.MaxFigures
789  this.fignr= 1;
790  fh = figure(this.Figures(1));
791  else
792  this.fignr= this.fignr + 1;
793  fh = figure(varargin[:]);
794  this.Figures(this.fignr) = fh;
795  end
796  this.cnt= numsubplots;
797  }
798 
799 
800  function finishCurrent() {
801  if ~this.donelast
802  h = this.curax;
803  if ishandle(h)
804  /* Set title and labels if given */
805  if ~isempty(this.ncap)
806  title(h,this.ncap);
807  end
808  if ~isempty(this.nxl)
809  xlabel(h, this.nxl);
810  end
811  if ~isempty(this.nyl)
812  ylabel(h, this.nyl);
813  end
814  if ~isempty(this.nleg)
815  legend(h, this.nleg[:]);
816  end
817  /* Make axis tight if no manual values have been set */
818  if ~any(strcmp(get(h,[" XLimMode "," YLimMode "," ZLimMode "])," manual "))
819  axis(h," tight ");
820  end
821  /* Check correct Y tickmarks */
822  this.checkTickMarks(h);
823  end
824  this.donelast= true;
825  end
826  }
834  function checkTickMarks(h) {
835  if this.AutoTickMarks
836  dims = [" X "," Y "]; /* ,'Z' */
837 
838  fields = [" Tick "," Scale "," TickLabel "," Data "," Lim "," TickMode "];
839  valign = [" top ", " middle "];
840  halign = [" center ", " right "];
841  f = struct;
842  codim = [2 1];
843  for dim=1:length(dims)
844  for fidx = 1:length(fields)
845  f(dim).(fields[fidx]) = [dims[dim] fields[fidx]];
846  end
847 
848  if strcmp(get(h,f(dim).Scale)," log ")
849  /* Get current effective limits */
850  [ymin, ymax] = getLimits(h, f(dim));
851 
852  if ~isempty(ymin) && ~isempty(ymax)
853  /* Delete old labels */
854  set(h,f(dim).TickLabel,[]);
855 
856  ylmi = ceil(log10(ymin));
857  ylma = floor(log10(ymax));
858  /* Usually: plot log scale in steps of one */
859  step = 1;
860  if ylma-ylmi < 3
861  /* Too few ticks: Double them */
862  step = .5;
863  ylmi = ylmi-step;
864  ylma = ylma+step;
865  elseif ylma-ylmi > 5
866  /* Too many ticks: Halfen them */
867  step = ceil((ylma-ylmi) / 4);
868  end
869  /* Determine tick steps */
870  expo = ylmi:step:ylma;
871  tick = 10.^(expo);
872 
873  /* Remove outliers */
874  valid = tick >= ymin & tick <= ymax;
875  tick(~valid) = [];
876  expo(~valid) = [];
877 
878  ticklbl = arrayfun(@(arg)sprintf(" \\textbf{$10^{%g}$} ",arg),expo," UniformOutput ",false);
879  colim = get(h,f(codim(dim)).Lim);
880  offset = 0.02;
881  text(ones(size(tick))*(colim(1)-offset*(colim(2)-colim(1))),...
882  tick,ticklbl," VerticalAlignment ",valign[dim],...
883  " HorizontalAlignment ",halign[dim]," interpreter "," LaTex ");
884  end
885  end
886  end
887  end
888 
889  function [minlim, maxlim] = getLimits(h, f)
890  minlim = Inf; maxlim = -Inf;
891  lines = findobj(get(h," Children ")," Type "," line ");
892  for k=1:length(lines)
893  d = get(lines(k),f.Data);
894  minlim = min(minlim, min(d(d~=0 & isfinite(d))));
895  maxlim = max(maxlim, max(d(d~=0 & isfinite(d))));
896  end
897  lim = get(h,f.Lim);
898  if lim(1) ~= 0 && isfinite(lim(1))
899  minlim = min(minlim, lim(1));
900  end
901  if lim(2) ~= 0 && isfinite(lim(2))
902  maxlim = max(maxlim, lim(2));
903  end
904  end
905  }
906 
907 
908  function [oldtitles , oldfonts ] = preSave(fig) {
909  allax = findobj(get(fig," Children ")," Type "," axes ");
910  /* Get title strings */
911  oldtitles = []; /* #ok<*AGROW> */
912 
913  childs = [" XLabel "," YLabel "," ZLabel "];
914  if this.NoTitlesOnSave
915  th = get(allax," Title ");
916  if numel(th) == 1, th = [th]; end
917  oldtitles = cellfun(@(th)get(th," String "),th,...
918  " UniformOutput ",false);
919  cellfun(@(th)set(th," String ",[]),th);
920  else
921  childs = [childs " Title "];
922  end
923  oldfonts = [];
924  if ~isempty(this.SaveFont)
925  for k = 1:length(allax)
926  ax = allax(k);
927  items = [ax cell2mat(get(ax,childs)) findobj(ax," Type "," text ")^t];
928  oldfonts[k] = get(items,fieldnames(this.SaveFont));
929  set(items,fieldnames(this.SaveFont),...
930  repmat(struct2cell(this.SaveFont)^t,numel(items),1));
931  end
932  end
933  }
934 
935 
936  function postSave(fig,oldtitles,oldfonts) {
937  allax = findobj(get(fig," Children ")," Type "," axes ");
938  /* Restore title strings */
939  childs = [" XLabel "," YLabel "," ZLabel "];
940  if this.NoTitlesOnSave
941  th = get(allax," Title ");
942  if numel(th) == 1, th = [th]; end
943  for k=1:length(th)
944  set(th[k]," String ",oldtitles[k]);
945  end
946  else
947  childs = [childs " Title "];
948  end
949  if ~isempty(this.SaveFont)
950  for k = 1:length(allax)
951  ax = allax(k);
952  items = [ax cell2mat(get(ax,childs)) findobj(ax," Type "," text ")^t];
953  set(items,fieldnames(this.SaveFont),oldfonts[k]);
954  end
955  end
956  }
957 
958 
959  function saveFigure(fig,rawfilename,extlist,xargs) {
960 
961  exts = [" fig "," pdf "," eps "," jpg "," png "," tif "," bmp "];
962  /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
963  formats = cell2mat(cellfun(@(arg)strcmp(exts,arg)^t,extlist,...
964  " UniformOutput ",false));
965  err = find(sum(formats)==0);
966  if ~isempty(err)
967  fprintf(2," Invalid extension(s): %s\n ",sprintf(" %s ",extlist[err]));
968  extlist(err) = [];
969  end
970  formats = sum(formats,2)^t;
971 
972  if ~isempty(rawfilename) && ~isempty(extlist)
973  /* check if directory exists and resolve relative paths (export_fig subfunctions
974  * somehow tend to break) */
975  seppos = strfind(rawfilename,filesep);
976  thedir = rawfilename(1:seppos(end)-1);
977  thefile = rawfilename(seppos(end)+1:end);
978  /* Does not work if filename contains dots!
979  *[thedir, thefile] = fileparts(rawfilename); */
980 
981  /* Special treatment for home directory, as the file name is wrapped into ""
982  * inside export_fig's commands. this prevents ~ from being resolved and thus
983  * the pdf/eps export fails. */
984  if isunix && thedir(1) == " ~ "
985  [~, homedir] = system(" echo ~ "); /* contains a linebreak, too */
986 
987  thedir = [homedir(1:end-1) thedir(2:end)];
988  end
989  /* Fix for mangled file paths */
990  jdir = java.io.File(thedir);
991  thedir = char(jdir.getCanonicalPath);
992  file = fullfile(thedir, thefile);
993  figpos = strcmp(extlist," fig ");
994  if any(figpos) /* fig */
995 
996  saveas(fig, [file " .fig "], " fig ");
997  extlist(figpos) = [];
998  end
999  if ~isempty(extlist)
1000  extlist = cellfun(@(e)sprintf(" -%s ",e),extlist," UniformOutput ",false);
1001  args = [file, extlist[:], sprintf(" -r%d ",this.ExportDPI)];
1002  if this.ExportDPI > 100
1003  args[end+1] = " -a2 ";
1004  end
1005  if any(formats & logical([0 1 1 0 1 0 0])) /* pdf, eps, png */
1006 
1007  args[end+1] = " -transparent ";
1008  elseif any(formats & logical([0 1 1 1 0 0 0])) /* jpg, eps, pdf */
1009 
1010  args[end+1] = [" -q " this.JPEGQuality];
1011  end
1012  args(end+1:end+length(xargs)) = xargs;
1013  args[end+1] = fig;
1014 
1015  if this.WhiteBackground
1016  pos = get(fig, " Position ");
1017  oldcol = get(fig, " Color ");
1018  set(fig, " Color ", " w ", " Position ", pos);
1019  end
1020 
1021  drawnow;
1022  export_fig(args[:]);
1023 
1024  if this.WhiteBackground
1025  set(fig, " Color ", oldcol, " Position ", pos);
1026  end
1027  end
1028  else
1029  fprintf(2," No file specified. Aborting\n ");
1030  end
1031  }
1042  public: /* ( Static ) */ /* ( Transient ) */
1043 
1044  static function pm = demo_SinglePlots() {
1045  pm = PlotManager;
1046  pm.LeaveOpen= true;
1047  pm.FilePrefix= " my_pm_single ";
1048 
1049  /* Here: Run your matlab script/code, do computations, etc
1050  * At some stage: Plotting is needed. Now call your plotting function/script with
1051  * the PlotManager argument. The big advantage of this is, that you can call your
1052  * plotting method with whatever setting to the PlotManager, so one time you have it
1053  * plotting to subplots (=development time) and the next you create single plots
1054  * with specific export settings (=publication/report time) */
1055 
1056  /* Inside your plotting method, create new axes using the nextPlot command. */
1057 
1058  h = pm.nextPlot(" plot1 "," Title of plot 1, look it has axes labels "," xlabel "," ylabel ");
1059  /* [.. do whatever plotting here using the axes handle h] */
1060  PlotManager.doPlot(h);
1061 
1062  h = pm.nextPlot(" plot2 "," Only title given ");
1063  /* [.. do whatever plotting here using the axes handle h] */
1064  PlotManager.doPlot(h);
1065 
1066  /* Finish off the current plot, which will add labels etc to it. */
1067  pm.done;
1068  }
1078  static function pm = demo_Subplots() {
1079  pm = PlotManager(false,2,2);
1080  pm.LeaveOpen= true;
1081  pm.FilePrefix= " my_pm_subplots ";
1082  /* [.. your plot function called with argument pm ..] */
1083  h = pm.nextPlot(" tag_of_subplot1 "," Title of subplot 1 "," xlabel "," ylabel ");
1084  PlotManager.doPlot(h);
1085  h = pm.nextPlot(" tag_of_subplot2 "," Only title given ");
1086  PlotManager.doPlot(h);
1087  h = pm.nextPlot(" tag_of_subplot3 "," title of subplot 3, no y label "," xlabel ",[],[" legend! "]);
1088  PlotManager.doPlot(h);
1089  pm.done;
1090  }
1091 
1092 
1093  static function pm = demo_SavePlots() {
1094  pm = PlotManager.demo_SinglePlots;
1095  pm.SaveFormats= [" jpg "," png "];
1096  pm.UseFileTypeFolders= false;
1097  pm.savePlots(pwd);
1098  pm.FilePrefix= " sameplots_withseparate_dir ";
1099  pm.UseFileTypeFolders= true;
1100  /* Disable saving of titles! */
1101  pm.NoTitlesOnSave= true;
1102  pm.savePlots(pwd," Close ",true);
1103  }
1104 
1105 
1106  static function pm = demo_SavePlots_Details() {
1107  pm = PlotManager.demo_SinglePlots;
1108  pm.UseFileTypeFolders= false;
1109  /* Add extra legend plot */
1110  h = pm.nextPlot(" withlegend "," Some plot with a legend! "," x "," y ",[" line 1 ", " line 2 ", " line 3 "]);
1111  x = -10:10;
1112  plot(h,x,[cos(x).*sin(x); cos(x); cosh(x)]);
1113 
1114  /* Save with specific format and separate legend */
1115  pm.savePlots(pwd," Format ",[" png "]," SeparateLegends ",[false false true]);
1116 
1117  /* Save under different file type, only a couple, and close ONLY THEM afterwards. */
1118  pm.savePlots(pwd," Format ",[" jpg "]," Selection ",[1 3]," Close ",true);
1119  }
1129  static function pm = demo_Zoom() {
1130  pm = PlotManager.demo_SinglePlots;
1131  /* Add extra legend plot */
1132  h = pm.nextPlot(" withlegend "," Some plot with a legend! "," x "," y ",[" line 1 ", " line 2 ", " line 3 "]);
1133  x = -10:.01:10;
1134  plot(h,x,[cos(x).*sin(x); cos(x); tanh(x)]);
1135  /* The latest figure number is three (so far got to know which is which) */
1136  pm.createZoom(3, [5 10], " zoom ");
1137  pm.createZoom(3, [-3 2], " zoom_nolegend ", false);
1138  pm.done;
1139  }
1140 
1141 
1142  private: /* ( Static ) */ /* ( Transient ) */
1143 
1144  static function doPlot(h) {
1145  r = RandStream(" mt19937ar "," Seed ",round(cputime*1000));
1146  fr = r.rand;
1147  x = linspace(-r.rand*5,r.rand*5,100);
1148  if fr < .3
1149  f = @(x,y)sin(y.*x/(3*r.rand*pi));
1150  elseif fr < .6
1151  f = @(x,y)log10(2*cosh(abs(x-y)).^(sin(x/r.rand*3)));
1152  else
1153  f = @(x,y)[r.rand*cos(x).*sin(y); pi*sin(x)];
1154  end
1155  if fr < .6 && r.rand < .5
1156  [X,Y] = meshgrid(x);
1157  surf(h,X,Y,f(X,Y)," EdgeColor "," None ");
1158  else
1159  plot(h,x,f(x,x.^2));
1160  end
1161  }
1177 };
1178 
logical NoTitlesOnSave
Flag that determines if any figures title's are removed when using savePlots.
Definition: PlotManager.m:199
function resetCount()
Resets the current axes handle count so that subsequent calls to "nextPlot" will result re-returnin...
Definition: PlotManager.m:706
integer ExportDPI
DPI used for export. See export_fig settings.
Definition: PlotManager.m:157
fields
Returns a cell array of string containing the names of public properties.
function savePlots(char folder, varargin)
Saves all plots that have been created thus far to a given folder with given format.
Definition: PlotManager.m:529
rowvec< double > FigureSize
The figure size for each newly created figure. Set to [] to use system default.
Definition: PlotManager.m:133
logical DoubleSaveJPG
For some reason on unix machines export_fig sometimes uses the last image saved to as the next one...
Definition: PlotManager.m:255
reshape
hanges the dimensions of the handle object array to the specified dimensions. See the MATLAB reshape ...
function h = copyFigure(nr, newtag)
Copies the plot with the given number and returns the handle to its axis.
Definition: PlotManager.m:448
An integer value.
PlotManager: Small class that allows the same plots generated by some script to be either organized a...
Definition: PlotManager.m:17
Matlab's base handle class (documentation generation substitute)
logical UseFileTypeFolders
Affects the savePlots behaviour. This flag lets the PlotManager create subfolders in the target folde...
Definition: PlotManager.m:179
A boolean value.
function done()
Finishes the current plotting process.
Definition: PlotManager.m:515
logical LeaveOpen
Flag indicating if the plots should be left open once the PlotManager is deleted (as variable) ...
Definition: PlotManager.m:213
A variable number of input arguments.
function h = createZoom(nr, area, tagextra, withlegend)
Definition: PlotManager.m:479
function axes ax_handle = nextPlot(char tag,char caption,char xlab,char ylab,cell< char > leg_str,integer numsubplots)
Creates a new axis to plot in. Depending on the property tools.PlotMananger.Single this will either a...
Definition: PlotManager.m:365
logical Single
Flag if single plots shall be used for subsequent calls to nextPlot.
Definition: PlotManager.m:109
Speed test * all(1:3)
logical WhiteBackground
Flag that determines if a white 'figure' background should be used instead of any set or default (gre...
Definition: PlotManager.m:268
function closeAll(selection)
Closes all currently openend plots and resets the Handles property.
Definition: PlotManager.m:680
integer MaxFigures
Controls the maximum number of simultaneously opened figures.
Definition: PlotManager.m:120
rowvec< integer > AutoTickMarks
An integer number to enforce a minimum number of tickmarks on the respective axes.
Definition: PlotManager.m:236
findobj
Finds objects matching the specified conditions from the input array of handle objects.
function res = isposintscalar(value)
isposintscalar: Backwards-compatibility function for matlab versions greater than 2012a ...
cell< char > SaveFormats
The image formats to use when savePlots is called.
Definition: PlotManager.m:224
PlotManager(logical single,integer rows,integer cols)
Creates a new PlotManager.
Definition: PlotManager.m:335
char FilePrefix
A prefix that has to be put before each file name for exported plots.
Definition: PlotManager.m:146
char JPEGQuality
JPEG quality used for export. See export_fig settings.
Definition: PlotManager.m:169
A MatLab character array.
rowvec< double > Figures
Provides access to all figure handles created using nextPlot.
Definition: PlotManager.m:288
function setFigureNames(name)
Definition: PlotManager.m:724
function matchPlotAxes(ax_handles, varargin)
Definition: PlotManager.m:734