Control the transparecny of axes

조회 수: 24 (최근 30일)
Hany Ferdinando
Hany Ferdinando 2025년 10월 7일 12:02
댓글: Hany Ferdinando 2025년 10월 10일 12:10
I would like to create a plot and put an inset axes to my original one like this:
Since the inset axes may block some parts of the graphics (see figure above), I would like to use alpha parameter to control its tranparency level.
set(gca, 'YTick', [], 'Color', 'w')
I tried the following but failed. Nothing changed.
set(gca, 'YTick', [], 'Color', 'w', 'ALimMode', 'manual', 'ALim', [.2 .5])

채택된 답변

Walter Roberson
Walter Roberson 2025년 10월 7일 14:52
이동: Walter Roberson 2025년 10월 7일 14:52
You can take advantage of the undocumented fact that commonly RGB triples can instead be RGB quads with the last value being alpha value.
However! Setting the alpha of lines this way is not permanent. It does not survive copying objects; it does not survive saving and restoring; it might not survive any automatic redraws (for example due to rescaling the axes, including because of adding more tiles.)
fig = figure();
ax1 = axes(fig);
plot(ax1, rand(10,15))
ax2 = axes(fig, 'position', [.5 .5 .3 .3], 'xcolor', [0 0 0 .3], 'ycolor', [0 0 0 .3], 'color', [1 1 1 .5])
ax2 =
Axes with properties: XLim: [0 1] YLim: [0 1] XScale: 'linear' YScale: 'linear' GridLineStyle: '-' Position: [0.5000 0.5000 0.3000 0.3000] Units: 'normalized' Use GET to show all properties
  댓글 수: 2
dpb
dpb 2025년 10월 7일 17:48
편집: dpb 2025년 10월 7일 17:56
"...the undocumented fact that commonly RGB triples can instead be RGB quads with the last value being alpha value."
Why this remains undocumented is a mystery; it's not like Mathworks could realistically change it. I suppose it's probably to do with the fact it is volatile as your note mentions.
Also, why the Axes doesn't have an exposed 'Alpha' property is baffling as well.
There is a hidden 'Backdrop' property of the axes, but it also doesn't have an 'Alpha' property nor is it an allowable object to the alpha function.
I think it would not be amiss to suggest adding 'Alpha' to the axes to be able to do this in a documented fashion as an enhancement, to provide something in between the present (documented) alternatives of 'Color','none' or a normal RGB color with default Alpha of 1.
Hany Ferdinando
Hany Ferdinando 2025년 10월 10일 12:10
Thanks Walter! Now I know why I could not find this information because it's not documented. Again, thanks for revealing this secret.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by