How to use stackedplot such that each graph has multiple lines AND x-axes is unevenly spaced continuous variable?
6 次查看(过去 30 天)
显示 更早的评论
I am attempting to create a stacked plot with three stacked plots/windows. I wish to include two lines on the first plot. In addition, I would like to be able to set the x-axis to be a specific vector of times that are not evenly spaced
0 个评论
回答(1 个)
Adam Danz
2021-12-14
编辑:Adam Danz
2021-12-16
> I wish to include two lines on the first plot.
It's easiest to work with tables or timetables when using stackedplot. If you're not already working with a table|timetable variable, convert your data to a table or timetable. Setting the VariableNames property of your table will provide axis labels to stackedplot.
% Create timetable
TT = array2timetable(rand(10,4)+[0 0 10 100],...
'RowTimes', datetime(2020,01,01,00,00,00) + minutes((0:9)'), ...
'VariableNames', {'A','B','C','D'})
% Specify column numbers for each axis
sph = stackedplot(TT,{[1,2],3,4});
> I would like to be able to set the x-axis to be a specific vector of times that are not evenly spaced
I assume you mean the x-axis-ticks. If you only want to select a specific set of rows of the table, you can achieve that by indexing the rows of the table. Example: stackedplot(TT(idx,:),___)
% To specify x-ticks
ax = findobj(sph.NodeChildren, 'Type','Axes'); % get axis handles
set(ax, 'XTick', TT.Time([1,4,6,9,10])) % set xtick
grid on % to show that xticks were applied to all axes
If you want to change the datetime format of the tick labels, use xtickformat(ax(1),'HH:mm:ss') or ax(1).XAxis.TickLabelFormat='HH:mm:ss';
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Data Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
