Issue with legend colours in scatter plots with tranparency set 'ON'
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I had set the Transparency to my scatter plot as shown in the below code. Unfrtunately, the marker colors are not visible in the legend. Is there any way to avoid this?
scatter (A(:,1),B(:,2),'MarkerEdgeAlpha',0.3,'MarkerFaceAlpha',0.4,'MarkerEdgeColor',C{1})
2 件のコメント
Voss
2024 年 3 月 15 日
The legend looks fine here:
A = [1;2;3];
B = [4 4; 5 5; 6 6];
C = {[1 0 1]};
scatter(A(:,1),B(:,2),'MarkerEdgeAlpha',0.3,'MarkerFaceAlpha',0.4,'MarkerEdgeColor',C{1})
legend
採用された回答
Star Strider
2024 年 3 月 15 日
The legend function has at least two other undocumented outputs (those are all that I experimented with, anyway), that can change the appearance of the legend marker and other properties.
Apparently just calling it with outputs is enough to set the marker in the legend to have an 'EdgeAlpha' property of 1, since that’s all I did here —
A = randn(4,1);
B = randn(4,2);
C = {[1 0 1]};
scatter (A(:,1),B(:,2),'MarkerEdgeAlpha',0.3,'MarkerFaceAlpha',0.4,'MarkerEdgeColor',C{1})
[hl1,hl2,hl3] = legend('Location','best');
The extra outputs have been used elsewhere to change the size of the marker in the legend. Setting the 'EdgeAlpha' property to 1 in one of those outputs (I believe it was ‘hl2(1)’) set the 'MarkerEdgeAlpha' property for all the markers to 1, obviously not the desired appearance. Otherwise, the legend marker seems to inherit all the marker properties that were originally set.
It could be worthwhile to explore those extra undocumented outputs (in other functions as well) to see what other options might be available.
Use the get function to see all the properties in each handle.
.
2 件のコメント
その他の回答 (1 件)
Voss
2024 年 3 月 15 日
編集済み: Voss
2024 年 3 月 15 日
The marker in the legend will be the same as what's in the plot. If you want them to be different, you can create a line with NaN data that's only used in the legend. Example:
A = [1;2;3];
B = [4 4; 5 5; 6 6];
C = {[1 0 1]};
scatter(A(:,1),B(:,2),'MarkerEdgeAlpha',0.1,'MarkerFaceAlpha',0.1,'MarkerEdgeColor',C{1})
h = line(NaN,NaN,'LineStyle','none','Marker','o','MarkerEdgeColor',C{1});
legend(h);
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!