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 Center および File ExchangeGraphics Object Properties についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by