フィルターのクリア

How can I shade my plot to the right of a given x value?

35 ビュー (過去 30 日間)
SSB
SSB 2014 年 6 月 1 日
コメント済み: A K M Kamrul Hasan 2020 年 1 月 22 日
I would like the plot area (under the plot lines) to be shaded grey to the right of x = 2.

回答 (2 件)

Star Strider
Star Strider 2014 年 6 月 2 日
編集済み: Star Strider 2014 年 6 月 2 日
Use the patch function. It takes a bit of experimenting to get it to do what you want, but it’s relatively easy.
To draw a gray box in specific axes, for example:
cm = [0 0 0 ; 0.5 0.5 0.5; 1 1 1];
figure(1)
patch([1 1 2 2 1]', [1 2 2 1 1]', cm(2,:))
axis([0 3 0 3])

Geoff Hayes
Geoff Hayes 2014 年 6 月 2 日
編集済み: Geoff Hayes 2014 年 6 月 2 日
The area function (type help area in the Command Window for details) can be used to shade in a portion of your plot to the right of a given x value. Consider the following example:
x = -4:0.1:4;
y = x.^2; % usual parabola
figure;
plot(x,y,'b');
% find the index of the element in x that is equal to two (works well for this
% example, but in other cases you may have to choose the index that you want to
% start the shading from)
idx = find(x==2);
% now colour the area in grey to the right of x==2
grey = [127 127 127]./255;
hold on;
area(x(idx:end),y(idx:end),'basevalue',0,'FaceColor',grey);
In the above, we use a subset of x and y to define the region that we want to shade in grey, starting at a base value of 0 (i.e. y==0).
  1 件のコメント
A K M Kamrul Hasan
A K M Kamrul Hasan 2020 年 1 月 22 日
Hi,
This discussion is about the srea bounded by straight lines. However, is it possible to shade an area in Matlab plot bounded by straight lines and curved lines? (i.e like the attached image) ?
Regards,1486289316.png

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePolygons についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by