How to combine existing tiled layout .fig files into a larger tiled layout?

45 views (last 30 days)
I have 10 separate figures, each of which has been created in the tiled layout format using a single tile. This was to have dual x and y axes on each figure. They were created elsewhere and saved as .fig files.
I need to combine them into a master figure with 5 rows and 2 columns. Each individual figure is a pcolor plot and they all have the same colormap, colorbar and colorbar title, so I would like to have just one colorbar (and colorbar title) instead of 10 tiny ones. I thought the best way to do this would be to have a "master" tiled layout, which each "sub" tile being one of the individual tiles.
I looked at some existing answers but they are for making the master tiled layout at the same time as the sub-tiles, whereas my sub-tiles are pre-existing .fig files that need to be loaded/imported and then copied over somehow.
I also looked at some existing answers on loading and combining previously saved figures into a subplot, but these were for "regular" figures, not tiled layouts with dual axes.
I would really appreciate any advice on how to do this, especially on what variables to copy from the original .fig files to what variables in the master tiled layout.
For clarity, I would expect the final code to be something like:
  1. import .fig files from folder on computer into array "figures"
  2. for each .fig file in "figures", extract the pcolour plot and both pairs of axes (each plot has two x and two y axes) and store these in array/matrix "extractedPlots"
  3. make a tiled layout
  4. for each plot in "extractedPlots", make a new tile in the tiled layout and plot the extracted pcolour plot and both pairs of axes saved in the current index in extractedPlots

Answers (1)

Rahul
Rahul on 11 Oct 2022
Edited: Rahul on 11 Oct 2022
Assuming you are using MATLAB R2019a or later, you can refer the following code. I have created four sample pcolor plots (in 2,2 matrix fashion) and created a common colorbar with colorbar string. Hope this helps. Please go through the documentation of "tiledlayout", and "colorbar" for more information.
[X,Y] = meshgrid(-3:6/17:3);
XX1 = 2*X.*Y;
YY1 = X.^2 - Y.^2;
colorscale = [1:18; 18:-1:1];
C1 = repmat(colorscale,9,1);
[X,Y] = meshgrid(1:20);
LY = log(Y);
colorscale = [1:20; 20:-1:1];
C = repmat(colorscale,10,1);
m = 2; % number of rows
n = 2; % number of columns
t = tiledlayout(m, n);
title(t,'Mater Tiled Layout Title', 'FontWeight', 'bold', 'FontSize', 18)
% Tile 1
nexttile
pcolor(XX1, YY1, C1)
title('Sample 1')
axis square
% Tile 2
nexttile
pcolor(X, Y, C)
title('Sample 2')
% Tile 3
nexttile
pcolor(XX1, YY1, C1)
title('Sample 3')
axis square
% Tile 4
nexttile
pcolor(X, Y, C)
title('Sample 4')
cb = colorbar;
cb.Layout.Tile = 'east'; % location of the colorbar
cb.Label.String = 'colorbar name'; % colorbar name (located sideways)
title(cb, 'Colorbar title', 'FontWeight', 'bold') % colorbar title (on top)
  2 Comments
Rahul
Rahul on 17 Oct 2022
Is it possible for you to share the fig files and/or the expected output (a rough sketch in Microsoft paint)?

Sign in to comment.

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by