フィルターのクリア

How can I program a section of my plot to have a different color background?

3 ビュー (過去 30 日間)
Tom Ruopp
Tom Ruopp 2016 年 3 月 10 日
コメント済み: Ced 2016 年 3 月 10 日
I plot lines along my data and I would like to make certain section in between them a different color. I have tried inserting a rectangle between them, but couldn't get it to be transparent (so that the data lines could still be seen). Is there a quick way to make the axis background a different color in between two x-axis values?
I have attached a sample plot to refer to.
  1 件のコメント
Ced
Ced 2016 年 3 月 10 日
I don't know how to set the background, but you can get your partially transparent rectangle with "patch", and then change the "FaceAlpha" value.
Example:
x = -1:0.1:1;
y = sin(x)
% define patch using vertices and color (normalized RGB)
h = patch([ 0 1 1 0 ],[0 0 1 1],[0.5 0.5 0 ]);
h.FaceAlpha = 0.5; % partially transparent
h.EdgeAlpha = 0; % we don't want the edge
hold on;
plot(x,y); % plot whatever you like
Note that if you create the patch before plotting, the curve is plotted "in front" of the patch, so you actually don't even need to set the transparency (except maybe for aesthetic reasons).

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

回答 (0 件)

カテゴリ

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