Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

savepng.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. function savepng(fighandle,fname,varargin)
  2. % savepng(fighandle, filename, [options])
  3. % Saves a pretty PNG.
  4. %
  5. % Inputs
  6. %
  7. % fighandle a figure handle to save
  8. % filename the full path and filename where it will be saved.
  9. %
  10. % Optional Inputs [defaults]
  11. %
  12. % dpi [180] this is ok for screen, for print should be 450 or 600
  13. % size [5, 5] 5 x 5 cm is good for a single panel.
  14. if nargin==0
  15. help('draw.savepng');
  16. return;
  17. end
  18. inpd = @utils.inputordefault;
  19. [dpi, varargin] = inpd('dpi', 180, varargin);
  20. [XMARGIN, varargin] = inpd('x_margin', 1.2, varargin);
  21. [YMARGIN, varargin] = inpd('y_margin', 1, varargin);
  22. [fsize, varargin] = inpd('size', [5,4], varargin);
  23. if ~isempty(varargin)
  24. fprintf(2,'Did not process the following inputs:\n');
  25. fprintf(2,'%s: %s\n',varargin{1:end});
  26. end
  27. %% Fix margins.
  28. % In order for the margins to work well, we need to make sure there is
  29. % enough space aroung the edge of all the axes.
  30. fighandle.Units = 'centimeters';
  31. set(fighandle.Children, 'Units','normalized');
  32. figpos = fighandle.Position;
  33. fighandle.Position = [figpos(1:2) fsize + [2*XMARGIN, 2*YMARGIN]];
  34. %
  35. % ch = get(fighandle, 'Children');
  36. % axpos = nan(numel(ch), 4);
  37. % shiftx = 0;
  38. % shifty = 0;
  39. % for cx = 1:numel(ch)
  40. % if isprop(ch(cx),'Type') && strcmp('axes',ch(cx).Type)
  41. % ch(cx).Units = 'centimeters';
  42. % pos = ch(cx).Position;
  43. % shiftx = max(shiftx, XMARGIN-pos(1));
  44. % shifty = max(shifty, YMARGIN-pos(2));
  45. % end
  46. % end
  47. %
  48. % fighandle.Position = fighandle.Position + [0, 0, shiftx, shifty];
  49. %
  50. % for cx = 1:numel(ch)
  51. % if isprop(ch(cx),'Type') && strcmp('axes',ch(cx).Type)
  52. % ch(cx).Position = ch(cx).Position + [shiftx, shifty, 0, 0];
  53. % end
  54. % end
  55. %
  56. fighandle.PaperUnits = 'centimeters';
  57. fighandle.PaperPosition = [0.5 0.5 fsize*1.5];
  58. fighandle.PaperSize = fsize*1.8;
  59. print(fighandle,'-dpng',sprintf('-r%d',dpi),fname)
  60. fighandle.Position = figpos;