MATLAB Answers

Share X and Y Axes for tiled layout plot

64 views (last 30 days)
Amanda Beatty
Amanda Beatty on 2 Mar 2021
Commented: Amanda Beatty on 9 Mar 2021
I have a tiled layout where each row has identical y-axes and each column has identical x axes. The labels are taking up space so I'd like to remove the duplicate axes numbers so I just have y-axis labels on the far left only, and x-axis labels on the bottom plots only.
Additionally, I'd love to have my y-label be separate for each row. Right now it's one label that I just put a bunch of spaces in between to space out the "Temperature" label and the "Delta from Baseline" label. If they could each be centered on their own row that would be great. I've been searching but I can't figure it out.
My code:
groupCount = length(groupNames); %count how many group there are
charts = tiledlayout(2,groupCount,'TileSpacing','Compact', 'Padding', 'compact'); %create figure for plotting
xlabel(charts,'Days on Test')
ylabel(charts, 'Delta from Baseline (pA) Temperature (C)')
for i = 1:length(data)
%Plot by group
groupPlotIdx(i) = find(strcmp(groupNames, data_analyzed(i).group)); %sort them all into groups
%temperature plot
tempPlot = nexttile(groupPlotIdx(i));
plot(data(i).temperatureTimestamp, data(i).temperature)
tempPlot.YLim = [35 44]; %set y axis limits
hold on
plot( data(i).temperatureTimestamp(startIdx),data(i).temperature(startIdx), '^k', 'MarkerFaceColor', 'k' ); %plot start point
hold on
%delta from baseline plot
signalPlot = nexttile(groupPlotIdx(i)+groupCount);
yline(0, '-k', 'LineWidth', 0.75);
plot(data(i).signalTimestamp, data_analyzed(i).signalNormalized)
signalPlot.YLim = [-200 100]; %set y axis limits
signalPlot.YTick = -200:50:100; %tick marks every 50pA
signalPlot.YMinorTick = 'on';
signalPlot.YGrid = 'on'; %turn on grid

More Answers (0)




Community Treasure Hunt

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

Start Hunting!