How to color RED to the lower portion of the curve

How to color RED to the lower portion of the curve y=x^2
x = 1 : 0.1 : 10;
y = x.^2;
plot(x,y)
axis([1 10 0 100])

 採用された回答

Kye Taylor
Kye Taylor 2013 年 4 月 18 日

1 投票

Replace the
plot(x,y)
command with
area(x,y,'FaceColor',[1 0 0])

6 件のコメント

Atom
Atom 2013 年 4 月 18 日
Thanks for this reply. It works good. If I want to color the upper region, then what should be the code?
Kye Taylor
Kye Taylor 2013 年 4 月 18 日
The command
patch(x,y,'b')
will add blue above the plot.
(How about showing a little love and accepting this answer.)
Atom
Atom 2013 年 4 月 18 日
編集済み: Atom 2013 年 4 月 18 日
Thanks a lot. Your 1st code is great. The second code patch(x,y,'b') colors the upper portion but not the whole upper part. The curve y = x.^2; divides the x-y plane in two parts. I want to color the whole upper part. Please suggest me once more.
With best regards and cordial thanks, Pallav
Kye Taylor
Kye Taylor 2013 年 4 月 18 日
Ohhh. i see what you mean. (I had my parabola symmetric about x = 0, and not just in the first quadrant). Try this
x = 1 : 0.1 : 10;
y = x.^2;
area(x,y,'FaceColor',[1,0,0])
patch([x,0],[y,100],'b')
axis([1 10 0 100])
Atom
Atom 2013 年 4 月 18 日
Please suggest about the meaning of patch([x,0],[y,100],'b').
Kye Taylor
Kye Taylor 2013 年 4 月 19 日
the first two inputs to patch can be thought of as points that define vertices of some polygon. the vectors x and y are the lower parts of that polygon. By adding a point (0,100) to the set of vertices, we get the top left corner of the polygon. Without that vertex, the behavior was as you said above, only the "upper portion" was colored instead of the "whole upper part".

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

タグ

質問済み:

2013 年 4 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by