How to shade a graph (full and some part)?

조회 수: 26 (최근 30일)
Nisar Ahmed
Nisar Ahmed 2021년 12월 20일
댓글: Star Strider 2022년 1월 3일
Hi,
In this figure, say a graph is plotted plot(a,b). First, how can I shade full graph in gray color (either left or right side) and then how to shade a small zone?

채택된 답변

Star Strider
Star Strider 2021년 12월 20일
Try something like this —
y = linspace(0,10); % Assume Row Vectors (Actual Data Not Provided)
x = randn(size(y));
yg = (y >= 2) & (y <= 4); % Special Shading Region
figure
plot(x, y)
xl = xlim;
hold on
patch([x, ones(size(x))*xl(2)], [y, flip(y)], [1 1 1]*0.75)
patch([x(yg), ones(size(x(yg)))*xl(2)], [y(yg), flip(y(yg))], [0 1 1]*0.85, 'EdgeColor','none')
hold off
If the vectors are column vectors, the easiest way to use my code with them would be to transpose them to row vectors and then use my code without significant changes to it. Define the ‘yg’ logical vector appropriately for the available data.
.
  댓글 수: 13
Nisar Ahmed
Nisar Ahmed 2022년 1월 3일
@Star Strider Dear thanks, it is working well. stay happy
Star Strider
Star Strider 2022년 1월 3일
As always, my pleasure!
Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polygons에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by