Plotting one curve with two colors

5 views (last 30 days)
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 :)

Accepted Answer

Star Strider
Star Strider on 20 Sep 2019
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
Yasmine Torkhani
Yasmine Torkhani on 20 Sep 2019
This works correctly!! Thank you :))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
Star Strider
Star Strider on 20 Sep 2019
As always, my pleasure!!!

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!