legend text is transparent in MATLAB R2018a

13 ビュー (過去 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 Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by