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
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
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.
.

更多回答(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);

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by