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

39 ビュー (過去 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 Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by