How to use stackedplot such that each graph has multiple lines AND x-axes is unevenly spaced continuous variable?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Adam Danz
il 14 Dic 2021
Modificato: Adam Danz
il 16 Dic 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 Commenti
Vedere anche
Categorie
Scopri di più su Discrete Data Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
