Control the transparecny of axes

24 visualizaciones (últimos 30 días)
Hany Ferdinando
Hany Ferdinando el 7 de Oct. de 2025 a las 12:02
Comentada: Hany Ferdinando el 10 de Oct. de 2025 a las 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])

Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de Oct. de 2025 a las 14:52
Movida: Walter Roberson el 7 de Oct. de 2025 a las 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 comentarios
dpb
dpb el 7 de Oct. de 2025 a las 17:48
Editada: dpb el 7 de Oct. de 2025 a las 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 el 10 de Oct. de 2025 a las 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Object Properties en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by