Highlight speicific hour of x-axis on matlab graph

조회 수: 4 (최근 30일)
Falak Naz
Falak Naz 2020년 5월 5일
편집: Mehmed Saad 2020년 5월 5일
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에서 Annotations에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by