Filter löschen
Filter löschen

set legend to non transparent

154 Ansichten (letzte 30 Tage)
Christopher Norrie
Christopher Norrie am 15 Aug. 2015
Beantwortet: Afiq Azaibi am 26 Apr. 2024
How is it possible to set a legends transparency to zero? i.e. completely opaque
Regards
  1 Kommentar
Matt J
Matt J am 10 Nov. 2016
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...

Melden Sie sich an, um zu kommentieren.

Antworten (3)

Cedric
Cedric am 16 Aug. 2015
Bearbeitet: Cedric am 16 Aug. 2015
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 am 16 Aug. 2015
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 am 26 Apr. 2024
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.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by