set legend to non transparent
조회 수: 118 (최근 30일)
이전 댓글 표시
How is it possible to set a legends transparency to zero? i.e. completely opaque
Regards
댓글 수: 1
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
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' )) ;
댓글 수: 0
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.
댓글 수: 0
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에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!