If we have 2 Legend's outputs, the "Number of Columns" option does not work

5 vues (au cours des 30 derniers jours)
Sim
Sim le 1 Juin 2023
Modifié(e) : Sim le 1 Juin 2023
Case 1. If we add the "Number of Columns" option to the Legend, and if we have 2 Legend's outputs, the number of columns does not change:
N = 100;
x = linspace(0,1,N);
y1 = repmat([-2;2],1,N);
y2 = repmat([-1;1],1,N);
figure; hold on;
h1 = fill([x flip(x)], [y1(1,:) flip(y1(2,:))],'r');
h2 = fill([x flip(x)], [y2(1,:) flip(y2(2,:))],'g');
ylim([-2,2]);
[first,second] = legend('area1','area2','NumColumns',2); % <-- 2 Legend's outputs
PatchInLegend = findobj(second, 'type', 'patch'); % <-- I need this part AND 'NumColumns',2
set(PatchInLegend(1), 'FaceAlpha', 0.2); % <-- I need this part AND 'NumColumns',2
set(PatchInLegend(2), 'FaceAlpha', 0.4); % <-- I need this part AND 'NumColumns',2
Case 2. If we add the "Number of Columns" option to the Legend, and if we have 1 Legend's output, the number of columns changes:
N = 100;
x = linspace(0,1,N);
y1 = repmat([-2;2],1,N);
y2 = repmat([-1;1],1,N);
figure; hold on;
h1 = fill([x flip(x)], [y1(1,:) flip(y1(2,:))],'r');
h2 = fill([x flip(x)], [y2(1,:) flip(y2(2,:))],'g');
ylim([-2,2]);
first = legend('area1','area2','NumColumns',2); % <-- 1 Legend's output
Question. How to make the "Number of Columns" option work if we have 2 Legend's outputs?

Réponse acceptée

Sim
Sim le 1 Juin 2023
Modifié(e) : Sim le 1 Juin 2023
I might have found a solution, but the "FaceAlpha" option acts on both the figure patches and the legend symbols:
N = 100;
x = linspace(0,1,N);
y1 = repmat([-2;2],1,N);
y2 = repmat([-1;1],1,N);
figure; hold on;
h1 = fill([x flip(x)], [y1(1,:) flip(y1(2,:))],'r');
h2 = fill([x flip(x)], [y2(1,:) flip(y2(2,:))],'g');
ylim([-2,2]);
first = legend('area1','area2','NumColumns',2);
PatchInLegend = findobj(first.PlotChildren, 'type', 'patch');
set(PatchInLegend(1), 'FaceAlpha', 0.2);
set(PatchInLegend(2), 'FaceAlpha', 0.4);

Plus de réponses (0)

Catégories

En savoir plus sur Specialized Power Systems dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by