Control the transparecny of axes
24 views (last 30 days)
Show older comments
Hany Ferdinando
on 7 Oct 2025 at 12:02
Commented: Hany Ferdinando
on 10 Oct 2025 at 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])
0 Comments
Accepted Answer
Walter Roberson
on 7 Oct 2025 at 14:52
Moved: Walter Roberson
on 7 Oct 2025 at 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])
2 Comments
dpb
on 7 Oct 2025 at 17:48
Edited: dpb
on 7 Oct 2025 at 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.
More Answers (0)
See Also
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!