Control the transparecny of axes

24 visualizzazioni (ultimi 30 giorni)
Hany Ferdinando
Hany Ferdinando il 7 Ott 2025 alle 12:02
Commentato: Hany Ferdinando il 10 Ott 2025 alle 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])

Risposta accettata

Walter Roberson
Walter Roberson il 7 Ott 2025 alle 14:52
Spostato: Walter Roberson il 7 Ott 2025 alle 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 Commenti
dpb
dpb il 7 Ott 2025 alle 17:48
Modificato: dpb il 7 Ott 2025 alle 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 il 10 Ott 2025 alle 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graphics Object Properties in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by