Deleting axes changes legend transparency?

2 ビュー (過去 30 日間)
Ben
Ben 2023 年 4 月 19 日
コメント済み: Ben 2023 年 4 月 28 日
I'm making a plot using gplotmatrix. I only need the lower half of the plot beneath the diagonal, so I have removed the upper half of the plot by setting the visibility of the axes and data points to 'off'.
However, in deleting these objects, the legend becomes slightly transparent, and after trying many fixes I have not been able to make the legend opaque.
I do not know if this is a bug or a feature, but any suggestions of how to remedy it are much appreciated. I've included before/after images as well as code that replicates this issue. Thanks!
x = rand(100,5);
group = zeros(100,1);
group(1:33) = 1;
group(34:66) = 2;
group(67:end) = 3;
figure(1)
[h,ax,bax] = gplotmatrix(x,[],group,[],[],[],'on','hist',[],[])
figure(2)
[h,ax,bax] = gplotmatrix(x,[],group,[],[],[],'on','hist',[],[])
% Remove axes in upper triangular portion of the gplotmatrix plot
for i = 1:5
for j = i+1:5
set(ax(i,j),'Visible','off');
set(findobj(ax(i,j),'type','line'),'Visible','off');
end
end
% Attempt (unsuccessfully) to force legend text color
leg = findobj(gcf,'Tag','legend')
set(leg,'Location','south','Orientation','horizontal','TextColor',[0, 0, 0, 1]);

採用された回答

Adam Danz
Adam Danz 2023 年 4 月 19 日
In gplotmatrix, the legend is associated with the axes in the upper right corner. When the visibility of that axes is off, the legend goes dim.
You can add a legend to a different axes but you'll need to create the names to appear in the legend.
[h,ax,bax] = gplotmatrix(x,[],group,[],[],[],'off','hist',[],[]);
% Don't add default legend ^^^
% Add legend to bottom left corner
legend(ax(end-1,1),{'1','2','3'})
  1 件のコメント
Ben
Ben 2023 年 4 月 28 日
Thanks Adam! I did this myself in the end but ended up making a modified version of the gplotmatrix function that changed the default plotting axis for the legend. Thanks again!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by