MATLAB Answers

0

Plotting one curve with two colors

Asked by Yasmine Torkhani on 20 Sep 2019 at 18:39
Latest activity Commented on by Star Strider
on 20 Sep 2019 at 20:20
Hello friends,
I want to plot my curve from 15.01.2018 until 14.10.2018 with a bright green and from 15.10.2018 until 15.07.2019 with a dark green. Can someone explain to me how can I do this?
Thank you in advance :)

  0 Comments

Sign in to comment.

1 Answer

Answer by Star Strider
on 20 Sep 2019 at 19:01
 Accepted Answer

Try this:
dnv = datenum({'15.01.2018','14.10.2018','15.10.2018','15.07.2019'}, 'dd.mm.yyyy'); % Limits
dn = dnv(1):dnv(end); % Continuous Dates Vector
s = sin(linspace(0, 2*pi, numel(dn))); % Create Dependent Variable Data
dnd{1} = (dn >= dnv(1)) & (dn <= dnv(2)); % Light Green Limits
dnd{2} = (dn >= dnv(3)) & (dn <= dnv(4)); % Dark Green Limits
figure
plot(dn(dnd{1}), s(dnd{1}), 'Color',[0.1 0.8 0.1], 'LineWidth',2)
hold on
plot(dn(dnd{2}), s(dnd{2}), 'Color',[0.1 0.5 0.1], 'LineWidth',2)
hold off
grid
datetick('x', 'dd.mm.yyyy', 'keepticks')
set(gca, 'XTickLAbelRotation', 30)
Experiment to get the result you want.
Plotting one curve with two colors - 2019 09 20.png

  6 Comments

Star Strider
on 20 Sep 2019 at 20:13
My pleasure.
I have absoluitely no idea what you want to do with respect to plotting which variables, so I just took a wild guess:
Try this:
D1 = load('NEGATIVESRL.mat');
D2 = load('POSITIVESRL.mat');
NEG = D1.NEG;
POS = D2.POS;
x = POS(:,1);
y1 = POS(:,2);
z1 = POS(:,3);
y2 = NEG(:,2);
z2 = NEG(:,3);
dnv = datenum({'15.01.2018','14.10.2018','15.10.2018','15.07.2019'}, 'dd.mm.yyyy'); % Limits
dnd{1} = (x >= dnv(1)) & (x <= dnv(2)); % Light Green Limits
dnd{2} = (x >= dnv(3)) & (x <= dnv(4)); % Dark Green Limits
h = zeros (5,1);
figure
h(1)= plot(x(dnd{1}), y1(dnd{1}), 'Color',[0.1 0.8 0.1]);
hold on
h(2)= plot(x(dnd{2}), y1(dnd{2}), 'Color',[0.1 0.5 0.1]);
h(3)= plot(x,y2);
h(4)= plot(x(179),y1(179),'rx');
h(5)= plot(x(180),y1(180),'bx');
h(6)= plot(x(274),y1(274),'y*');
hold off
axis = [737075,737621,-250,1500];
xticks([737075 737253 737621])
dateFormat = 28;
datetick('x',dateFormat)
title ('Entwicklung der SRL Leistungspreise')
ylabel('Leistungspreise [€/MW]')
xlabel('Zeit (pro Tag)')
legend(h,'SRL POS_1','SRL POS_2','SRL NEG','12.07.2018','13.07.2018','15.10.2018')
Change it to get the result you want.
This works correctly!! Thank you :))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
Star Strider
on 20 Sep 2019 at 20:20
As always, my pleasure!!!

Sign in to comment.