フィルターのクリア

set legend to non transparent

158 ビュー (過去 30 日間)
Christopher Norrie
Christopher Norrie 2015 年 8 月 15 日
回答済み: Afiq Azaibi 2024 年 4 月 26 日
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 Center および File ExchangeLegend についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by