set legend to non transparent

115 次查看(过去 30 天)
Christopher Norrie
Christopher Norrie 2015-8-15
How is it possible to set a legends transparency to zero? i.e. completely opaque
Regards
  1 个评论
Matt J
Matt J 2016-11-10
I wonder if this was in reference to plots generated with plotyy? I have recently generated a case where the legend box is opaque with respect to the left hand plots and transparent with respect to the right hand plots. No idea how to adjust this. The axis Color properties don't make any difference...

请先登录,再进行评论。

回答(3 个)

Cedric
Cedric 2015-8-16
编辑:Cedric 2015-8-16
What do you mean by opaque? By default the legend is boxed and opaque:
>> t = 0 : 0.1 : 10 ; plot( t, sin(t), 'b', t, cos(t), 'r' ) ; grid on ;
>> lh = legend( {'sin', 'cos'} ) ;
where lh stands for legend handle.
Then you can modify properties:
>> set( lh )
Box: {'on' 'off'}
BusyAction: {'queue' 'cancel'}
ButtonDownFcn: {}
Children: {}
Color: {1x0 cell}
CreateFcn: {}
DeleteFcn: {}
EdgeColor: {1x0 cell}
FontAngle: {'normal' 'italic'}
FontName: {}
FontSize: {}
FontWeight: {'normal' 'bold'}
HandleVisibility: {'on' 'callback' 'off'}
HitTest: {'on' 'off'}
Interpreter: {'none' 'tex' 'latex'}
Interruptible: {'on' 'off'}
LineWidth: {}
Location: {1x19 cell}
Orientation: {'horizontal' 'vertical'}
Parent: {}
PickableParts: {'visible' 'none' 'all'}
Position: {}
Selected: {'on' 'off'}
SelectionHighlight: {'on' 'off'}
String: {}
Tag: {}
TextColor: {1x0 cell}
UIContextMenu: {}
Units: {'inches' 'centimeters' 'characters' 'normalized' 'points' 'pixels'}
UserData: {}
Visible: {'on' 'off'}
e.g. to remove the box, or to remove the box edges. Without the box the background is transparent:
>> set( lh, 'Box', 'off' ) ;
If you want an opaque background, e.g. grey, without edge, keep it boxed and change the edge color to match the (background) color :
>> set( lh, 'Box', 'on', 'Color', [0.8,0.8,0.8], 'EdgeColor', get( lh, 'Color' )) ;

Walter Roberson
Walter Roberson 2015-8-16
When I read the documentation in R2014a (older graphics style) and R2015a (newer graphics style) I see no evidence that there is any transparency associated with legends. When I test with R2014a, none of the generated objects has any capacity for transparency, including the hidden objects.

Afiq Azaibi
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.
Rectangle also has a new FaceAlpha property and you can read more about both in this blog post.

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by