How to have MATLAB 2016 Legend without box and as transparent?
33 次查看(过去 30 天)
显示 更早的评论
My proposal but I cannot get it work in MATLAB 2016b
f = figure;
hax = axes(f);
[BL,BLicons] = legend(hax, 'lorem');
% http://stackoverflow.com/a/26459062/54964
PatchInLegend = findobj(BLicons, 'type', 'patch');
set(PatchInLegend, 'facea', 0.5);
Syntax in Docs correspond to icons as `[lgd,icons,plots,txt] = legend(_)`.
Expected output: no box around the legend and transparency.
I have also tried unsuccessfully; which is what I have literally
[BL, BLicons] = legend( bFigHax, sprintf('Tc'), 'Box', 'off', ...
'Location', 'southwest', 'color', 'none');
MATLAB: 2016b OS: Debian 8.5
0 个评论
回答(2 个)
Kirby Fears
2016-10-24
编辑:Kirby Fears
2016-10-24
SL,
Check out the Matlab documentation on the legend function. Special arguments can be passed in as name value pairs when creating the legend. https://www.mathworks.com/help/matlab/ref/legend.html#namevaluepairarguments
The full list of names you can specify values for is here: https://www.mathworks.com/help/matlab/ref/legend-properties.html
The box can be removed by specifying
legend(...,'Box','off');
I don't see any options to make the legend background transparent, but you can change the background color using the 'Color' argument. The transparency setting you found on stackoverflow is specifically referring to the transparency of the green color patches displayed within the legend shown. If that's what you're after, their example should work.
2 个评论
Kirby Fears
2016-10-25
编辑:Kirby Fears
2016-10-25
SL,
Please describe what happens when you execute your legend command. What exactly is not working? There should at least be no boundary box.
Also, check that your other input arguments are valid. For example, are you trying to specify a single legend label 'Tc', because that's what you're specifying.
sprintf('Tc') % evaluates to string 'Tc'
ans =
'Tc'
Have you verified that bFixHax is the correct axis handle?
Afiq Azaibi
2024-4-26
Starting in R2024a, legend supports the ability to control the level of transparency with the BackgroundAlpha property. Below is a short example:
plot(magic(7));
grid on;
set(gca, 'Color', [.88 .88 .88]);
l = legend(BackgroundAlpha=.7);
Setting the value to 0 will make it fully transparent and a value 1 of will make it fully opaque which is the default behavior.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!