legend text is transparent in MATLAB R2018a

조회 수: 12 (최근 30일)
Dylan Catlett
Dylan Catlett 2019년 4월 22일
댓글: Dylan Catlett 2019년 4월 23일
I recently updated Matlab from R2015b to R2018a and now I am unable to re-create the legends on some of my plots. The problem is that in the new plots, the legend text is transparent. I've tried modifying properties of the legend manually to no avail.
Here's the R2015b code and resulting plot.
counter = 1;
figure(); hold on;
for i = 1:7;
stIDX = idx_allSt(:,i);
for j = 1:12;
mIDX = idx_allM{j};
idx = ismember(stIDX,mIDX);
idx = stIDX(idx);
scatter(all_AFs_ds(idx,3),all_AFs_ds(idx,4),st_symbols{i},'MarkerEdgeColor',monthly_colors(j,:));
end
counter = counter + 1;
end
% for making a station legend:
for i = 1:7;
h(i) = plot(0,0,st_symbols{i},'Color','k','visible','off');
end
l = legend(h, 'St 1', 'St 2', 'St 3', 'St 4', 'St 5', 'St 6', 'St 7');
ax = gca; ax.XLabel.String = 'PC 1 [mixed upwelling community -->]'; ax.YLabel.String = 'PC 2 [diatom bloom -->]';
% for making a custom colormap by month (still working on it):
c = colorbar; colormap(COLORS); caxis([1 12]); c.Ticks = 1:12;
c.TickLabels = {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'};
% plot zero-lines:
x = ax.XLim; x = x(1):x(length(x)); y = zeros(length(x),1); plot(x,y,'k');
x = ax.YLim; x = x(1):x(length(x)); y = zeros(length(x),1); plot(y,x,'k');
title('Pigments - Mode 1 vs. Mode 2');
Screen Shot 2019-04-22 at 3.25.08 PM.png
You can see the legend has the typical black font, and that in the second for-loop in the above code snippet, I was able to create the legend so that it only included the 7 entries I wanted and displayed them all in black.
When I do this in R2018a (with a modified code snippet to attempt to manually set the text to appear black and/or bold), I get the following:
counter = 1;
figure(); hold on;
for i = 1:7;
stIDX = idx_allSt(:,i);
for j = 1:12;
mIDX = idx_allM{j};
idx = ismember(stIDX,mIDX);
idx = stIDX(idx);
scatter(all_AFs_ds(idx,3),all_AFs_ds(idx,4),st_symbols{i},'MarkerEdgeColor',monthly_colors(j,:));
end
counter = counter + 1;
end
ax = gca; ax.XLabel.String = 'PC 1'; ax.YLabel.String = 'PC 2';
% for making a station legend:
for i = 1:7;
h(i) = plot(0,0,st_symbols{i},'Color','k','visible','off');
end
% for making a custom colormap by month (still working on it):
c = colorbar; colormap(COLORS); caxis([1 12]); c.Ticks = 1:12;
c.TickLabels = {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'};
% plot zero-lines:
x = ax.XLim; x = x(1):x(length(x)); y = zeros(length(x),1); plot(x,y,'k');
x = ax.YLim; x = x(1):x(length(x)); y = zeros(length(x),1); plot(y,x,'k');
title('R2018a');
l = legend(h, 'St 1', 'St 2', 'St 3', 'St 4', 'St 5', 'St 6', 'St 7');
Screen Shot 2019-04-22 at 3.31.15 PM.png
The legend text is now slightly transparent. Why? I've tried adding the following lines but the transparency in the legend text remains. I can't seem to find any explanations or work-arounds for this in R2018a, so any help would be much-appreciated.
l.HandleVisibility = 'off'; % have also tried 'on'
l.TextColor = 'k'; l.Color = 'w'; l.EdgeColor = 'k';
l.FontSize = 14; l.FontWeight = 'bold';

채택된 답변

Jan
Jan 2019년 4월 23일
편집: Jan 2019년 4월 23일
Instead of plotting invisible points, use this:
h(i) = plot(NaN, NaN, st_symbols{i}, 'Color', 'k');
By the way, I have no idea why you assume, that this code migth help:
l.HandleVisibility = 'off'; % have also tried 'on'
l.TextColor = 'k'; l.Color = 'w'; l.EdgeColor = 'k';
l.FontSize = 14; l.FontWeight = 'bold';
The HandleVisibility controls, if the handle is hidden or not. This does not influence the optical appearence.
  댓글 수: 1
Dylan Catlett
Dylan Catlett 2019년 4월 23일
Thank you, Jan, and apologies for the duplicate question.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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