How to plot 4 Tiled plots with 2 x axis and 2 y axis in one figure
47 views (last 30 days)
Show older comments
I want to plot 4 tiled diagrams in one figure. I already use tiledlayout to creat a secon x axis. The first diagram is correct, but when I try to plot the second diagram next to the first (using tiled layout again) only an empty diagram appears and the data from the second diagram are plottet in the first diagram.
How can i plot 4 of those diagramms like the first in one figure?
% Al2O3 für alle EF
% EF 4 mm
tmp = readtable('project.xlsx', 'Sheet', '4');
x1= table2array(tmp(:,12));
y1= table2array(tmp(:,2));
x2= table2array(tmp(:,25))
y2= table2array(tmp(:,15));
y3= table2array(tmp(:,3));
y4= table2array(tmp(:,16));
figure()
t = tiledlayout(2,3);
t1=tiledlayout(t,1,1)
ax1 = axes(t);
plot(ax1,x1,y1,'or')
ax1.XColor = 'r';
ax1.YColor = 'r';
set ( gca,'XLim', [0, 4])
xlabel('Thickness [mm]')
ylabel('w/w [%]')
ax2 = axes(t);
plot(ax2,x2,y2,'ok')
ax2.XAxisLocation = 'top';
ax2.YAxisLocation = 'right';
ax2.Color = 'none';
ax1.Box = 'off';
ax2.Box = 'off';
set ( gca,'XLim', [0, 4], 'XDir', 'reverse' )
set ( gca,'YLim', [0, 0.525])
xlabel('Thickness [mm]')
ylabel('w/w[%]')
nexttile;
t2=tiledlayout(t,1,1)
ax1 = axes(t);
plot(ax1,x1,y2,'or')
ax1.XColor = 'r';
ax1.YColor = 'r';
set ( gca,'XLim', [0, 4])
xlabel('Thickness [mm]')
ylabel('w/w [%]')
ax2 = axes(t);
plot(ax2,x2,y3,'ok')
ax2.XAxisLocation = 'top';
ax2.YAxisLocation = 'right';
ax2.Color = 'none';
ax1.Box = 'off';
ax2.Box = 'off';
set ( gca,'XLim', [0, 4], 'XDir', 'reverse' ) % Hier muss hintere Zahl mit Glas-Dicke (Nenndicke) übereinstimmen
xlabel('Thickness [mm])')
ylabel('w/w [%]')
3 Comments
Stephen23
2 minutes ago
Rather than creating a sub-table and then calling TABKE2ARRAY like this:
x1 = table2array(tmp(:,12));
a simpler way to obtain the table content is to use curly-brace indexing:
x1 = tmp{:,12};
Answers (1)
Stephen23
about 4 hours ago
Do NOT call TILEDLAYOUT multiple times.
Only call TILEDLAYOUT once. After that you call NEXTTILE for each plot.
"I want to plot 4 tiled diagrams in one figure."
Your code specifies two rows and three columns, which thus makes space for six plots:
t = tiledlayout(2,3);
whereas if you really want four plots then you should specify two rows and two columns:
tiledlayout(2,2); % call only ONCE!
[X,Y,Z] = peaks(20);
% Tile 1
nexttile
surf(X,Y,Z)
% Tile 2
nexttile
contour(X,Y,Z)
% Tile 3
nexttile
imagesc(Z)
% Tile 4
nexttile
plot3(X,Y,Z)
7 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!