How to shade time intervall

6 vues (au cours des 30 derniers jours)
Martin Muehlegger
Martin Muehlegger le 9 Jan 2020
I would like to shade specific time ranges(intervalls) which are created from a datamatrix in a for loop according to there indexes. I have the datetimes (begin and end of the intervall)
the Face (should be alpha = 0.2) and the y axis could be the whole plot domain or even better +- a certain mean value which I have as well.
goal is to have 5 different patches/areas on my timeseries
patch doesn't support datetime
fill/area etc. I couldn't find any satisfying solution
figure('DefaultAxesFontSize',15);
x = date;
y = CAL.stick_Data.stick_duty_cps;
k = 1; % placeholder in loop plot for row of CalibrationA(:,1)
idx=1;
for m= Markeridx'
hold all;
plot(x(:,k),y(:,m));
set(gca,'TickLabelInterpreter','latex')
set(gcf,'units','points','position',[100,100,700,500]) % figure position on screen and size is the saved figuresize!
caption = sprintf('y = %f * x + %f', p(1), p(2));
text(xt, yt, caption, 'FontSize', 12, 'Color', 'k', 'FontWeight', 'bold','interpreter','latex');
xlabel('ppbv ','interpreter','latex'); %FC_cal/FC_zeroair *1000
ylabel('cps','interpreter','latex');
idx = idx+1;
end
legend({'21.02264', '33.03350', '39.03321', '42.03382',...
'45.03350', '59.04914', '63.02629', '69.06988', '73.06480',...
'78.04640', '79.05422', '81.06988', '87.08045', '93.06988',...
'107.08553', '121.10118', '135.11683', '137.13248', '203.94361',...
'330.84809'})
a = axes;
t1 = title('Gas calibration dilution steps from subset A','interpreter','latex'); % Make sure to change titel after changing susbets
a.Visible = 'off'; % set(a,'Visible','off');
t1.Visible = 'on'; % set(t1,'Visible','on');
filter(1) = area([datetime(CALtime(1,3)) datetime(CALtime(1,end)) datetime(CALtime(1,end)) datetime(CALtime(1,3))],'FaceColor','r','Edgecolor','none', 'FaceAlpha',.3);
hold off;
Here is my figure without the shaded areasfigure.jpg

Réponse acceptée

Star Strider
Star Strider le 9 Jan 2020
Try this:
time = datetime('17:00','InputFormat','HH:mm'):minutes(1):datetime('18:00','InputFormat','HH:mm'); % Create Vector
time.Format = 'HH:mm';
cps = randn(1, numel(time))*0.1 + sin(2*pi*(0:numel(time)-1)/45); % Create Vector
fillfcn = @(timerange,colour,lo,hi) fill([time(timerange) fliplr(time(timerange))], [ones(size(time(timerange)))*lo ones(size(time(timerange)))*hi], colour, 'FaceAlpha',0.2); % Function Ot Create ‘fill’ Regions
figure
plot(time, cps)
hold on
fillfcn((10:20), 'r', 0.5, 1.2)
fillfcn((30:50), 'g', -1.3, -0.7)
hold off
With the test code, it produces:
How to shade time intervall - 2020 01 09.png
Experiment to get the result you want.

Plus de réponses (0)

Catégories

En savoir plus sur Data Exploration dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by