Multiple y and x-axes in multiple subplots.
11 次查看(过去 30 天)
显示 更早的评论
Hi,
for a work project I'm trying to create multiple subplots which each have multiple y and x-axes. I know I have probably use the tiledlayout function, but I think the double usage of that function messes it up. I want to plot the array-pairs Cl_Skiiii5, height5 and Echo_1h, Posi_55 in the first subplot and Cl_Skiiii6, height6 and Echo_2h, Posi_56 in the next. This is my code so far:
f=figure;
t = tiledlayout(1,2);
ax1 = axes(t);
ax2 = axes(t);
p1=plot(ax1,Cl_Skiiii5, height5,'-r');hold on
ax1.XColor = 'k';
ax1.YColor = 'k';
p2=plot(ax2,Echo_1h, Posi_55 , '--^r');hold on
ax2.XAxisLocation = 'top';
ax2.YAxisLocation = 'right';
ax2.Color = 'none';
ax2.YColor = 'none';
ax1.Box = 'off';
ax2.Box = 'off';
hold off
ax1 = nexttile(2);
ax2 = nexttile(2);
p1=plot(ax1,Cl_Skiiii6, height6,'-r');hold on
ax1.XColor = 'k';
ax1.YColor = 'k';
p2=plot(ax2, Echo_2h, Posi_56 , '--^r');hold on
ax2.XAxisLocation = 'top';
ax2.YAxisLocation = 'right';
ax2.Color = 'none';
ax2.YColor = 'none';
ax1.Box = 'off';
ax2.Box = 'off';
hold off
Can somebody help? I used part of the code to create one plot with muliple axes quite successfully, but once I tried to also implement diffenrent subplots everything became jumbled.
Thanks in advance
Ben
0 个评论
回答(1 个)
Deepak
2024-9-10
As I understand, you are trying to create multiple subplots, each having multiple axes. You want to plot arrays (Cl__Skiii5, height5) and (Echo_1h, Posi_55) in the first subplot, and the arrays (Cl__Skiii6, height6) and (Echo_2h, Posi_56) in the second subplot.
To achieve this, we can use “tiledlayout” and “nexttile” functions in MATLAB. The “tiledlayout” function is used to define the grid layout for plots; we can specify the number of rows and columns in the grid. The “nexttile” function is used to select a subplot in the layout for plotting. Each call to “nexttile” moves to the next tile in the grid, allowing us to plot different datasets in each section.
Below is the complete MATLAB code that addresses the task:
% Create a tiled layout with 1 row and 2 columns
f = figure;
t = tiledlayout(1, 2);
% First subplot
ax1 = nexttile(t);
plot(ax1, Cl_Skiiii5, height5, '-r'); % First plot
hold on;
plot(ax1, Echo_1h, Posi_55, '--^b'); % Second plot
ax1.XColor = 'k';
ax1.YColor = 'k';
ax1.Box = 'off';
hold off;
% Second subplot
ax2 = nexttile(t);
plot(ax2, Cl_Skiiii6, height6, '-r'); % First plot
hold on;
plot(ax2, Echo_2h, Posi_56, '--^g'); % Second plot
ax2.XColor = 'k';
ax2.YColor = 'k';
ax2.Box = 'off';
hold off;
title(t, 'Multiple Plots on Single Axes');
Please find attached documentation of functions used for reference:
I hope this helps to accomplish the task.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axes Appearance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!