Saving a Plot on a Figure with Transparency Ignores the Transparency

17 ビュー (過去 30 日間)
Jason
Jason 2023 年 4 月 17 日
コメント済み: Dave B 2023 年 4 月 19 日
Hello, I am trying to replicate some of Excels fancy plots in Matlab. In particular when I plot data, Im also plotting the same data but with a thicker line and transparency reduced to give the effect of "glow"
I use the Color 4th parameter for the this (the 1st 3 are RGB colour, and the 4th is the Alpha value)
i.e
p=plot(ax,xdata,ydata,'LineWidth',14,'Color',cl); % cl = a pre assigned colour
p.Color(4) = 0.11;
This is actually plotted on a UIAxes. I then copy this to a figure which allows me to save the "fancy" graph. However, Im noticing that transparency isn't saving.
Here is the graph copied to a figure - that I then save with the save button
But when I reopen that saved figure, as I said the transparency isn't saved.
Is there a way to get the graph saved exactly how it appears?
Thanks
Jason

採用された回答

Dave B
Dave B 2023 年 4 月 17 日
Transparency for lines isn't supported, and so the alpha channel is lost when you save and load. A workaround is to use patch, which does support transparency.
However, one thing to watch out for with the 'thick line for glow' strategy is sharp turns, the line will overlap with itself making a little bright spot. You can see a few little overlaps in the sine wave, and some bigger ones in the sawtooth below. You could avoid this by actually making a region (e.g. using patch and FaceColor/FaceAlpha properties), but you'd need to compute how far to offset that region from the line in data co-ordinates...
x=linspace(0,2*pi,100);
y=sin(x);
clr = [.85 .325 .098];
plot(x,y,'Color',clr)
p=patch([x flip(x)],[y flip(y)],clr);
p.EdgeColor=clr;
p.FaceColor='none';
p.EdgeAlpha=.15;
p.LineWidth=7;
p.LineJoin='round'; % to make it similar to plot's default
ax=gca;
ax.Color=[.1 .1 .1];
ylim padded
figure
x=linspace(0,5*pi,11);
y=sin(x);
clf;hold on
clr = [.85 .325 .098];
plot(x,y,'Color',clr)
p=patch([x flip(x)],[y flip(y)],clr);
p.EdgeColor=clr;
p.FaceColor='none';
p.EdgeAlpha=.15;
p.LineWidth=7;
p.LineJoin='round';
ax=gca;
ax.Color=[.1 .1 .1];
ylim padded
  2 件のコメント
Jason
Jason 2023 年 4 月 18 日
Thankyou Dave, this is excellent. Out of interest, do you know if there is any plan to include the ability to save transparency with "plot" in future releases?
Dave B
Dave B 2023 年 4 月 19 日
I'm afraid I don't know the answer to that question, but I do know that it's been requested and that requests from users are very important to us!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by