Control Whiskers on Boxchart or add legend to Boxplot

15 visualizzazioni (ultimi 30 giorni)
Hi,
I'm trying to create a boxplot where the whiskers extend to the actual max and min. This is possible using boxplot, not with boxchart.
At the same time, I want to use the colored grouping and add a legend for the colors. This is possible using boxchart, not with boxplot.
Is there a solution I do not see?

Risposte (1)

Jaynik
Jaynik il 27 Set 2023
Hi Martin,
I understand that you are trying to extend whiskers in the boxchart and add legend for colors in the boxplot and are facing issues with it. There is no direct way possible to perform both tasks. As for adding a colored legend, you can search for the box object and add the legend entry for each box.
data = [randn(100,1) rand(100, 1) rand(100, 1)]; % Initialize a random data
figure;
boxplot(data, 'Colors', 'rbg', 'Labels', {'Group 1', 'Group 2', 'Group 3'});
h = findobj(gca, 'Tag', 'Box');
legendEntries = cell(1, size(data, 2)); % Create a cell array for legend entries
for i = 1:size(data, 2)
legendEntries{i} = ['Variable ' num2str(i)];
end
legend(h, legendEntries);
For grouping data for boxplot, you will need to perform manual adjustments in the code. Also, boxplot only accepts numeric data; for data in table format, you will need to use boxchart.
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by