Highlight speicific hour of x-axis on matlab graph

1 次查看(过去 30 天)
I basically want to highlight the area from location 10 to 13 on x-axis, right now its highling the whole area
clear all;
close all;
clc
x = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24];
y = [0 184.24 184.24 184.24 180.54 180.54 12.77 12.77 12.77 5.40 5.40 5.40 5.40 5.40 5.40 5.40 5.40 5.40 5.40 3.00 3.00 3.00 3.00 3.00 3.00 ];
y1 = [0 136.24 136.24 136.24 133.54 9.77 9.77 9.77 9.77 3.40 3.40 3.40 3.40 3.40 3.40 3.40 3.40 3.40 3.40 3.00 3.00 3.00 3.00 3.00 3.00 ];
subplot(1,2,1);
plot(x,y,x,y1,'LineWidth',1.75)
title('Total Electric Load');
xlabel('Time in hour'); ylabel('Electic Load (KWH)');
legend('A','B');
ax = gca;
c = ax.Color;
ax.Color = 'blue'
alpha(0.8);
grid;
xlim([0.5 24])
ylim([0 220])
hold off;

回答(1 个)

Mehmed Saad
Mehmed Saad 2020-5-5
编辑:Mehmed Saad 2020-5-5
You are changing the color of axis and not highlighting a specific portion of plot. For that purpose you can use fill or patch.
for example i want to create a rectangle fill bw x = [1 2] and y = [4 5]
figure,
fill([1 2 2 1],[4 4 5 5],'b','EdgeColor','none','FaceAlpha',0.5)
xlim([0 3]),ylim([3 6])
By playing with fill you can acheive graph below

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by