MultiPanel.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. function PanelHandles = MultiPanel(FigureHandle, Dimension, Margins, InterPanelSpacing, LetterSize, PanelLetters, LetterFontSize)
  2. if ~exist('LetterFontSize', 'var')
  3. LetterFontSize = 12;
  4. end
  5. NumberOfPanelRows = Dimension(1);
  6. NumberOfPanelColumns = Dimension(2);
  7. RightMargin = Margins(2);
  8. LeftMargin = Margins(1);
  9. TopMargin = Margins(4);
  10. BottomMargin = Margins(3);
  11. if sum(LetterSize > 0) % have letter axes size, stuck between other spaces
  12. LetterWidth = LetterSize(1);
  13. LetterHeight = LetterSize(2);
  14. else % have letter axes position, overlaying other spaces
  15. LetterWidth = 0;
  16. LetterHeight = 0;
  17. LetterX = LetterSize(1);
  18. LetterY = LetterSize(2);
  19. end
  20. InterPanelWidth = InterPanelSpacing(1);
  21. InterPanelHeight = InterPanelSpacing(2);
  22. PanelWidth = (1 - (LeftMargin + NumberOfPanelColumns*LetterWidth + (NumberOfPanelColumns - 1) * InterPanelWidth + RightMargin)) / NumberOfPanelColumns;
  23. PanelHeight = (1 - (BottomMargin + (NumberOfPanelRows - 1) * InterPanelHeight + NumberOfPanelRows * LetterHeight + TopMargin)) / NumberOfPanelRows;
  24. PanelHandles = nan(NumberOfPanelRows, NumberOfPanelColumns);
  25. figure(FigureHandle)
  26. for Row = 1:NumberOfPanelRows
  27. for Column = 1:NumberOfPanelColumns
  28. % create panel
  29. PanelHandles(Row, Column) = axes('Position', [LeftMargin + LetterWidth + (Column - 1) * (LetterWidth + InterPanelWidth + PanelWidth) ...
  30. BottomMargin + (NumberOfPanelRows - Row) * (LetterHeight + InterPanelHeight + PanelHeight) ...
  31. PanelWidth PanelHeight]);
  32. % put panel letter (if desired)
  33. if ~isempty(PanelLetters{Row, Column})
  34. if sum(LetterSize > 0)
  35. axes('Position', [LeftMargin + (Column - 1) * (LetterWidth + InterPanelWidth + PanelWidth) ...
  36. BottomMargin + PanelHeight + (NumberOfPanelRows - Row) * (LetterHeight + InterPanelHeight + PanelHeight) ...
  37. LetterWidth LetterHeight], 'visible', 'off')
  38. else
  39. MainAxesPosition = get(PanelHandles(Row, Column), 'Position');
  40. axes('Position', [MainAxesPosition(1) + LetterX, MainAxesPosition(2) + MainAxesPosition(4) - LetterY, eps, eps])
  41. end
  42. set(gca, 'visible', 'off')
  43. text(0.5, 0.5, PanelLetters{Row, Column}, 'FontSize', LetterFontSize, 'VerticalAlign', 'middle', 'HorizontalAlign', 'center', 'FontWeight', 'bold')%
  44. end
  45. end
  46. end