Hi,
Is it possible to automatically alter the transparency of colors using the fill command?
For example, I would want to use:
fill (x,y, 'r');
but make the red color transparent.
Thanks!

3 件のコメント

Sean de Wolski
Sean de Wolski 2011 年 5 月 12 日
What's the point of filling it if it's going to be transparent? Why not just plot?
Jessica
Jessica 2011 年 5 月 12 日
I want to see the picture behind the colors.
Sean de Wolski
Sean de Wolski 2011 年 5 月 12 日
Ahh, translucent...

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

回答 (2 件)

Matt Fig
Matt Fig 2011 年 5 月 12 日

3 投票

t = (1/16:1/8:1)'*2*pi;
x = sin(t);
y = cos(t);
h = fill(x,y,'r');
% Choose a number between 0 (invisible) and 1 (opaque) for facealpha.
set(h,'facealpha',.5)
Also, see the edgealpha property of h. Look at set(h) to see all the properties you can set.

5 件のコメント

Jessica
Jessica 2011 年 5 月 12 日
Hi,
Thanks so much for the tip!
Do you know how to make the borders of the polygon still standout and not be transparent too?
h4=fill (X_Polygon7, Y_Polygon7,'r');
set(h4,'facealpha',.5)
line (X_Polygon7, Y_Polygon7,'LineWidth', 3, 'Color','k');
I have multiple polygons adjacent to each other and sometimes they overlap. However, I would like to have bolder lines tracing them but they appear transparent too.
Matt Fig
Matt Fig 2011 年 5 月 12 日
Yes, this is why I mentioned the other properties for you to look at, did you do so?
t = (1/16:1/8:1)'*2*pi;
x = sin(t);
y = cos(t);
h = fill(x,y,'r');
% Choose a number between 0 (invisible) and 1 (opaque) for facealpha.
set(h,'facealpha',.5)
set(h,'linewidth',3)
Now if your next question is how to change the line color, look at the edgecolor property.
Jessica
Jessica 2011 年 5 月 12 日
So the problem is that the lines appear transparent too. I uploaded the output to my profile picture. You can see that the black line down the middle is sometimes transparent.
Matt Fig
Matt Fig 2011 年 5 月 12 日
I cannot reproduce the problem. Could you describe the data more? For example, are the black lines the boundaries of one long skinny patch object squeezed between two larger patches? Or are they the boundaries of the larger patch objects? If you can't find a work around, you might be better off setting the edgecolor to none and plotting the edges by using the LINE function. For example:
t = (1/16:1/8:1)'*2*pi;
x = sin(t);
y = cos(t);
h = fill(x,y,'r','edgecolor','none');
set(h,'facealpha',.5)
X = [x;x(1)];
Y = [y;y(1)];
line(X,Y,'color','k','linewidth',3) % Make the edges...
Jessica
Jessica 2011 年 5 月 12 日
The black line down the middle is outlining the edge of two polygons that are adjacent to each other.
The only way I have found a way around this is to save the image. And then pull up the saved image and draw the lines atop it again. However, this is not very simple because the image is not saved with the same dimensions as the original so I need to bring it into photoshop to change the dimensions first. My original image is large so the file "export_fig" did not work to save the figure with the original dimensions.

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

Teja Muppirala
Teja Muppirala 2011 年 5 月 12 日

2 投票

Just for fun, and because windowbuttonmotionfcns are totally underappreciated:
t = (1/16:1/8:1)'*2*pi;
x = sin(t);
y = cos(t);
h = fill(x,y,'r');
F = @(x) alpha(max(min(x,1),0));
set(gcf,'windowbuttonmotionfcn','F( ([1 0]*get(gca,''currentp'')*[0;1;0] - min(ylim)) / diff(ylim) )')

1 件のコメント

Matt Fig
Matt Fig 2011 年 5 月 12 日
編集済み: madhan ravi 2018 年 11 月 23 日
Nice! I prefer symmetry myself:
t = (1/16:1/8:1)'*2*pi;
x = sin(t);
y = cos(t);
h = fill(x,y,'r');
axis square
set(gcf,'windowbuttonmotionfcn','set(h,''facealpha'',min(1,abs(norm(get(gca,''currentpoint''),''fro'')-sqrt(2))))')

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

カテゴリ

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

タグ

質問済み:

2011 年 5 月 12 日

編集済み:

2018 年 11 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by