createPrintFig.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. function hFig = createPrintFig(figSize)
  2. % Defaults for this fig.
  3. width = figSize(1); % Width in centimeters
  4. height = figSize(2); % Height in centimeters
  5. alw = 0.75; % AxesLineWidth
  6. fsz = 11; % Fontsize
  7. lw = 2; % LineWidth
  8. msz = 6; % MarkerSize
  9. graphicsRoot = groot;
  10. if size(graphicsRoot.MonitorPositions, 1) == 2
  11. monitorPos = graphicsRoot.MonitorPositions(2, :);
  12. elseif size(graphicsRoot.MonitorPositions, 1) == 1
  13. monitorPos = graphicsRoot.MonitorPositions(1, :);
  14. end
  15. defaultPos = [monitorPos(1:2) + 10 (monitorPos(3:4) - 100)];
  16. % The properties we've been using in the figures
  17. set(0, 'defaultLineLineWidth', lw); % set the default line width to lw
  18. set(0, 'defaultLineMarkerSize', msz); % set the default line marker size to msz
  19. %% Set the default Size for display
  20. % defaultPos = figPos;% get(0, 'defaultFigurePosition');
  21. % set(0, 'defaultFigurePosition', [defaultPos(1), defaultPos(2), width * 100, height * 100]);
  22. hFig = figure;
  23. hFig.Position = [defaultPos(1), defaultPos(2), ...
  24. min(width * 75, defaultPos(3)) min(height * 75, defaultPos(4))];
  25. %% Set the defaults for saving/printing to a file
  26. % set(0, 'defaultFigureInvertHardcopy', 'on'); % This is the default anyway
  27. % set(0, 'defaultFigurePaperUnits', 'centimeters'); % This is the default anyway
  28. hFig.InvertHardcopy = 'on';
  29. hFig.PaperUnits = 'centimeters';
  30. if 0
  31. defaultPaperSize = get(0, 'defaultFigurePaperSize');
  32. else
  33. hFig.PaperSize = [width height];
  34. defaultPaperSize = [width height];
  35. end
  36. left = (defaultPaperSize(1) - width) / 2;
  37. bottom = (defaultPaperSize(2) - height) / 2;
  38. % defaultPaperSize = [left, bottom, width, height];
  39. % set(0, 'defaultFigurePaperPosition', defaultPaperSize);
  40. hFig.PaperPosition = [left, bottom, width, height];
  41. end