How to use stackedplot such that each graph has multiple lines AND x-axes is unevenly spaced continuous variable?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Adam Danz
am 14 Dez. 2021
Bearbeitet: Adam Danz
am 16 Dez. 2021
> 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 Kommentare
Siehe auch
Kategorien
Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
