Issue with legend colours in scatter plots with tranparency set 'ON'

3 ビュー (過去 30 日間)
Turbulence Analysis
Turbulence Analysis 2024 年 3 月 15 日
コメント済み: Voss 2024 年 3 月 15 日
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
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
Turbulence Analysis
Turbulence Analysis 2024 年 3 月 15 日
Hi,
That's with when MarkerEdgeAlpha and MarkerfaceAlpha being set to gerather than 0.4. But If I set the both to 0.1, the marker on the legend becomes very dull/ invisble

サインインしてコメントする。

採用された回答

Star Strider
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 件のコメント
Turbulence Analysis
Turbulence Analysis 2024 年 3 月 15 日
WoW! Thanks very much!
Star Strider
Star Strider 2024 年 3 月 15 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Voss
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);
  2 件のコメント
Turbulence Analysis
Turbulence Analysis 2024 年 3 月 15 日
Thanks!
Voss
Voss 2024 年 3 月 15 日
You're welcome!

サインインしてコメントする。

カテゴリ

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