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

조회 수: 3 (최근 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
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.
.

추가 답변 (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